加密 @param data 待加密数据 @param key 密钥 @return byte[] 加密数据 @throws Exception
(byte[] data, byte[] key)
| 158 | * @throws Exception |
| 159 | */ |
| 160 | public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { |
| 161 | |
| 162 | // 生成本地密钥 |
| 163 | SecretKey secretKey = new SecretKeySpec(key, SECRET_KEY_ALGORITHM); |
| 164 | |
| 165 | // 数据加密 |
| 166 | Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm()); |
| 167 | |
| 168 | cipher.init(Cipher.ENCRYPT_MODE, secretKey); |
| 169 | |
| 170 | return cipher.doFinal(data); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * 解密<br> |
nothing calls this directly
no test coverage detected