MCPcopy Create free account
hub / github.com/SeanDragon/protools / ToolDESede

Class ToolDESede

security/src/main/java/pro/tools/security/ToolDESede.java:21–143  ·  view source on GitHub ↗

DESede安全编码组件 @author SeanDragon

Source from the content-addressed store, hash-verified

19 * @author SeanDragon
20 */
21public final class ToolDESede {
22 private ToolDESede() {
23 throw new UnsupportedOperationException("我是工具类,别初始化我。。。");
24 }
25
26 /**
27 * 密钥算法
28 */
29 public static final String KEY_ALGORITHM = "DESede";
30
31 /**
32 * 加密/解密算法 / 工作模式 / 填充方式 Java 6支持PKCS5PADDING填充方式 Bouncy
33 * Castle支持PKCS7Padding填充方式
34 */
35 public static final String CIPHER_ALGORITHM = "DESede/ECB/PKCS5Padding";
36
37 /**
38 * 转换密钥
39 *
40 * @param key
41 * 二进制密钥
42 *
43 * @return Key 密钥
44 *
45 * @throws Exception
46 */
47 private static Key toKey(byte[] key) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException {
48
49 // 实例化DES密钥材料
50 DESedeKeySpec dks = new DESedeKeySpec(key);
51
52 // 实例化秘密密钥工厂
53 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(KEY_ALGORITHM);
54
55 // 生成秘密密钥
56 SecretKey secretKey = keyFactory.generateSecret(dks);
57
58 return secretKey;
59 }
60
61 /**
62 * 解密
63 *
64 * @param data
65 * 待解密数据
66 * @param key
67 * 密钥
68 *
69 * @return byte[] 解密数据
70 *
71 * @throws Exception
72 */
73 public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, BadPaddingException, IllegalBlockSizeException {
74
75 // 还原密钥
76 Key k = toKey(key);
77
78 /*

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected