加解密文档里没有JSON的案例,研究一下XML加解密就能看出来只要把XML取数据的地方换成JSON取数据的就可以了
@Slf4j
public class AESUtils {
/**
* 对密文进行解密.
*
* @param text 需要解密的密文
* @return 解密得到的明文
* @throws AesException aes解密失败
*/
public static String decrypt(String text) throws AesException {
byte[] original;
byte[] aesKey = Base64.decodeBase64(WeChatRest.mesKey);
try {
// 设置解密模式为AES的CBC模式
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16));
SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES");
cipher.init(Cipher.DECRYPT_MODE, key_spec, iv);
// 使用BASE64对密文进行解码
byte[] encrypted = Base64.decodeBase64(text);
// 解密
original = cipher.doFinal(encrypted);
} catch (Exception e) {