转换密钥 @param password 密码 @return Key 密钥 @throws Exception
(String password)
| 80 | * @throws Exception |
| 81 | */ |
| 82 | private static Key toKey(String password) throws NoSuchAlgorithmException, InvalidKeySpecException { |
| 83 | // 密钥材料转换 |
| 84 | PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray()); |
| 85 | |
| 86 | // 实例化 |
| 87 | SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM); |
| 88 | |
| 89 | // 生成密钥 |
| 90 | SecretKey secretKey = keyFactory.generateSecret(keySpec); |
| 91 | |
| 92 | return secretKey; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * 加密 |
no test coverage detected