初始化甲方密钥 @return Map 甲方密钥Map @throws Exception
()
| 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); |
| 92 | |
| 93 | keyMap.put(PUBLIC_KEY, publicKey); |
| 94 | keyMap.put(PRIVATE_KEY, privateKey); |
| 95 | |
| 96 | return keyMap; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * 初始化乙方密钥 |
nothing calls this directly
no test coverage detected