解密 @param data 待解密数据 @param key 密钥 @return byte[] 解密数据 @throws Exception
(byte[] data, byte[] key)
| 76 | * @throws Exception |
| 77 | */ |
| 78 | public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { |
| 79 | // 还原密钥 |
| 80 | Key k = toKey(key); |
| 81 | |
| 82 | /* |
| 83 | * 实例化 使用PKCS7Padding填充方式,按如下方式实现 Cipher.getInstance(CIPHER_ALGORITHM, "BC"); |
| 84 | */ |
| 85 | Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); |
| 86 | |
| 87 | // 初始化,设置为解密模式 |
| 88 | cipher.init(Cipher.DECRYPT_MODE, k); |
| 89 | |
| 90 | // 执行操作 |
| 91 | return cipher.doFinal(data); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * 加密 |
nothing calls this directly
no test coverage detected