加密 @param data 数据 @param password 密码 @param salt 盐 @return byte[] 加密数据 @throws Exception
(byte[] data, String password, byte[] salt)
| 107 | * @throws Exception |
| 108 | */ |
| 109 | public static byte[] encrypt(byte[] data, String password, byte[] salt) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { |
| 110 | |
| 111 | // 转换密钥 |
| 112 | Key key = toKey(password); |
| 113 | |
| 114 | // 实例化PBE参数材料 |
| 115 | PBEParameterSpec paramSpec = new PBEParameterSpec(salt, HASH_BIT_SIZE); |
| 116 | |
| 117 | // 实例化 |
| 118 | Cipher cipher = Cipher.getInstance(ALGORITHM); |
| 119 | |
| 120 | // 初始化 |
| 121 | cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec); |
| 122 | |
| 123 | // 执行操作 |
| 124 | return cipher.doFinal(data); |
| 125 | |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * 解密 |
nothing calls this directly
no test coverage detected