1 /*
2 * This file is part of Waarp Project (named also Waarp or GG).
3 *
4 * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5 * tags. See the COPYRIGHT.txt in the distribution for a full listing of
6 * individual contributors.
7 *
8 * All Waarp Project is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * Waarp . If not, see <http://www.gnu.org/licenses/>.
19 */
20 package org.waarp.common.crypto;
21
22 /**
23 * This class handles methods to crypt and decrypt messages with DES algorithm
24 * (very efficient: 40000/s).<br>
25 * <br>
26 * Usage:<br>
27 * <ul>
28 * <li>Create a Des object: Des key = new Des();</li>
29 * <li>Create a key:
30 * <ul>
31 * <li>Generate: key.generateKey();<br>
32 * The method key.getSecretKeyInBytes() allow getting the key in Bytes.</li>
33 * <li>From an external source: key.setSecretKey(arrayOfBytes);</li>
34 * </ul>
35 * </li>
36 * <li>To crypt a String in a Base64 format: String myStringCrypt =
37 * key.cryptToString(myString);</li>
38 * <li>To decrypt one string from Base64 format to the original String: String
39 * myStringDecrypt =
40 * key.decryptStringInString(myStringCrypte);</li>
41 * </ul>
42 */
43 public class Des extends KeyObject {
44 /**
45 * This value could be between 32 and 128 due to license limitation.
46 */
47 private static final int KEY_SIZE = 56; // [32..448]
48 private static final String ALGO = "DES";
49 private static final String INSTANCE = "DES/ECB/PKCS5Padding";
50 public static final String EXTENSION = "des";
51
52 @Override
53 public final String getAlgorithm() {
54 return ALGO;
55 }
56
57 @Override
58 public final String getInstance() {
59 return INSTANCE;
60 }
61
62 @Override
63 public final int getKeySize() {
64 return KEY_SIZE;
65 }
66
67 @Override
68 public final String getFileExtension() {
69 return EXTENSION;
70 }
71 }