1 |
35292
|
stefania.m
|
package eu.dnetlib.client;
|
2 |
|
|
|
3 |
|
|
import com.googlecode.gwt.crypto.bouncycastle.DataLengthException;
|
4 |
|
|
import com.googlecode.gwt.crypto.bouncycastle.InvalidCipherTextException;
|
5 |
|
|
import com.googlecode.gwt.crypto.client.TripleDesCipher;
|
6 |
|
|
|
7 |
|
|
/**
|
8 |
|
|
* Created by stefania on 3/8/15.
|
9 |
|
|
*/
|
10 |
|
|
public class Crypto {
|
11 |
|
|
|
12 |
|
|
public static final byte[] GWT_DES_KEY = new byte[]{
|
13 |
|
|
(byte)254,(byte)65,(byte)23,(byte)198,(byte)16,(byte)5,(byte)239,(byte)45,
|
14 |
|
|
(byte)111,(byte)90,(byte)8,(byte)174,(byte)39,(byte)85,(byte)216,(byte)157,};
|
15 |
|
|
|
16 |
|
|
public static String encrypt(String stringToEncrypt) {
|
17 |
|
|
|
18 |
|
|
String encryptedString = null;
|
19 |
|
|
|
20 |
|
|
TripleDesCipher cipher = new TripleDesCipher();
|
21 |
|
|
cipher.setKey(GWT_DES_KEY);
|
22 |
|
|
|
23 |
|
|
try {
|
24 |
|
|
|
25 |
|
|
encryptedString = cipher.encrypt(stringToEncrypt);
|
26 |
|
|
|
27 |
|
|
} catch (DataLengthException e) {
|
28 |
|
|
e.printStackTrace();
|
29 |
|
|
} catch (IllegalStateException e) {
|
30 |
|
|
e.printStackTrace();
|
31 |
|
|
} catch (InvalidCipherTextException e) {
|
32 |
|
|
e.printStackTrace();
|
33 |
|
|
} catch (Exception e) {
|
34 |
|
|
e.printStackTrace();
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
return encryptedString;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
public static String decrypt(String stringToDecrypt) {
|
41 |
|
|
|
42 |
|
|
String decryptedString = null;
|
43 |
|
|
|
44 |
|
|
TripleDesCipher cipher = new TripleDesCipher();
|
45 |
|
|
cipher.setKey(GWT_DES_KEY);
|
46 |
|
|
|
47 |
|
|
try {
|
48 |
|
|
|
49 |
|
|
decryptedString = cipher.decrypt(stringToDecrypt);
|
50 |
|
|
|
51 |
|
|
} catch (DataLengthException e) {
|
52 |
|
|
e.printStackTrace();
|
53 |
|
|
} catch (IllegalStateException e) {
|
54 |
|
|
e.printStackTrace();
|
55 |
|
|
} catch (InvalidCipherTextException e) {
|
56 |
|
|
e.printStackTrace();
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
return decryptedString;
|
60 |
|
|
}
|
61 |
|
|
}
|