· 9 years ago · Nov 07, 2016, 06:22 AM
1/*
2* AES Decryption
3*/
4protected static byte[] CalcAES(byte[] data, byte[] key){
5 try {
6 SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
7 Cipher cipher = Cipher.getInstance("AES");
8 cipher.init(Cipher.DECRYPT_MODE, secretKey);
9 return cipher.doFinal(data);
10 } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
11 | BadPaddingException | IllegalBlockSizeException e) {
12 e.printStackTrace();
13 }
14 return null;
15}
16
17/*
18* DES Decryption
19*/
20public static byte[] CalcDES(byte[] input, byte[] KeySrc){
21
22 try {
23 SecureRandom random = new SecureRandom();
24 DESKeySpec spec = new DESKeySpec(KeySrc);
25 SecretKey DESKey = SecretKeyFactory.getInstance("DES").generateSecret(spec);
26 Cipher cipher = Cipher.getInstance("DES");
27 cipher.init(Cipher.DECRYPT_MODE, DESKey, random);
28 return cipher.doFinal(input);
29 } catch (InvalidKeySpecException | NoSuchAlgorithmException | NoSuchPaddingException |
30 InvalidKeyException | BadPaddingException | IllegalBlockSizeException e) {
31 e.printStackTrace();
32 }
33
34 return null;
35}
36
37/*
38* MD5
39*/
40public static byte[] CalcMD5(byte[] intput) {
41 byte[] output;
42 try {
43 MessageDigest messageDigest = MessageDigest.getInstance("MD5");
44 messageDigest.update(intput);
45 output = messageDigest.digest();
46 }
47 catch(NoSuchAlgorithmException e) {
48 e.printStackTrace();
49 output = null;
50 }
51
52 return output;
53}