生成密钥 @return 密钥对象 @throws Exception
()
| 137 | * @throws Exception |
| 138 | */ |
| 139 | public static Map<String, Object> initKey() throws NoSuchAlgorithmException { |
| 140 | // 初始化密钥对儿生成器 |
| 141 | KeyPairGenerator keygen = KeyPairGenerator.getInstance(ALGORITHM); |
| 142 | |
| 143 | // 实例化密钥对儿生成器 |
| 144 | keygen.initialize(KEY_SIZE, new SecureRandom()); |
| 145 | |
| 146 | // 实例化密钥对儿 |
| 147 | KeyPair keys = keygen.genKeyPair(); |
| 148 | |
| 149 | DSAPublicKey publicKey = (DSAPublicKey) keys.getPublic(); |
| 150 | |
| 151 | DSAPrivateKey privateKey = (DSAPrivateKey) keys.getPrivate(); |
| 152 | |
| 153 | // 封装密钥 |
| 154 | Map<String, Object> map = Maps.newHashMapWithExpectedSize(2); |
| 155 | |
| 156 | map.put(PUBLIC_KEY, publicKey); |
| 157 | map.put(PRIVATE_KEY, privateKey); |
| 158 | |
| 159 | return map; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * 取得私钥 |
nothing calls this directly
no test coverage detected