DES加密成功,解密出错:Given final block not properly padded. Such issues can arise if a bad key is used durin

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编码了,所以解密的时候先解码

Java DES3加密,包含密钥,日期偏移量,明文

发布了172 篇原创文章 · 获赞 64 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/WeiHao0240/article/details/103023110