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

Class ToolDH

security/src/main/java/pro/tools/security/ToolDH.java:34–277  ·  view source on GitHub ↗

DH安全编码组件 @author SeanDragon

Source from the content-addressed store, hash-verified

32 * @author SeanDragon
33 */
34public final class ToolDH {
35 private ToolDH() {
36 throw new UnsupportedOperationException("我是工具类,别初始化我。。。");
37 }
38
39 /**
40 * 非对称加密密钥算法
41 */
42 public static final String KEY_ALGORITHM = "DH";
43
44 /**
45 * 本地密钥算法,即对称加密密钥算法,可选DES、DESede和AES算法
46 */
47 public static final String SECRET_KEY_ALGORITHM = "AES";
48
49 /**
50 * 默认密钥长度
51 * <p>
52 * DH算法默认密钥长度为1024 密钥长度必须是64的倍数,其范围在512到1024位之间。
53 */
54 private static final int KEY_SIZE = 512;
55
56 /**
57 * 公钥
58 */
59 private static final String PUBLIC_KEY = "DHPublicKey";
60
61 /**
62 * 私钥
63 */
64 private static final String PRIVATE_KEY = "DHPrivateKey";
65
66 /**
67 * 初始化甲方密钥
68 *
69 * @return Map 甲方密钥Map
70 *
71 * @throws Exception
72 */
73 public static Map<String, Object> initKey() throws NoSuchAlgorithmException {
74
75 // 实例化密钥对生成器
76 KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM);
77
78 // 初始化密钥对生成器
79 keyPairGenerator.initialize(KEY_SIZE);
80
81 // 生成密钥对
82 KeyPair keyPair = keyPairGenerator.generateKeyPair();
83
84 // 甲方公钥
85 DHPublicKey publicKey = (DHPublicKey) keyPair.getPublic();
86
87 // 甲方私钥
88 DHPrivateKey privateKey = (DHPrivateKey) keyPair.getPrivate();
89
90 // 将密钥对存储在Map中
91 Map<String, Object> keyMap = Maps.newHashMapWithExpectedSize(2);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected