初始化密钥 @return Map 密钥Map @throws Exception
()
| 205 | * @throws Exception |
| 206 | */ |
| 207 | public static Map<String, Object> initKey() throws NoSuchAlgorithmException { |
| 208 | // 实例化密钥对生成器 |
| 209 | KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); |
| 210 | |
| 211 | // 初始化密钥对生成器 |
| 212 | keyPairGen.initialize(KEY_SIZE); |
| 213 | |
| 214 | // 生成密钥对 |
| 215 | KeyPair keyPair = keyPairGen.generateKeyPair(); |
| 216 | |
| 217 | // 公钥 |
| 218 | RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); |
| 219 | |
| 220 | // 私钥 |
| 221 | RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); |
| 222 | |
| 223 | // 封装密钥 |
| 224 | Map<String, Object> keyMap = Maps.newHashMapWithExpectedSize(2); |
| 225 | |
| 226 | keyMap.put(PUBLIC_KEY, publicKey); |
| 227 | keyMap.put(PRIVATE_KEY, privateKey); |
| 228 | |
| 229 | return keyMap; |
| 230 | } |
| 231 | |
| 232 | } |
nothing calls this directly
no test coverage detected