DES加密成功,解密出错:Given final block not properly padded. Such issues can arise if a bad key is used durin
解决方案:
//1.首先看看你加密返回的是不是这样:
byte[] encryptData = cipher.doFinal(data.getBytes(encoding));
return Base64.getEncoder().encodeToString(encryptData);
//2.如果是,恭喜你,解密的时候只要这样:
byte[] decryptData = cipher.doFinal(Base64.getDecoder().decode(data.getBytes(encoding)));
return new String(decryptData, "GB2312");
//因为原本他应该返回字节数组的,你给Base64编码了,所以解密的时候先解码