AES解密异常Given final block not properly padded-在线助手博客
Posted chenshouyin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AES解密异常Given final block not properly padded-在线助手博客相关的知识,希望对你有一定的参考价值。
AES 128/192/256位CBC/CFB/ECB/OFB/PCBC 在线加密解密
解密内容:1243CFEBD819AA6B1C717DE870459F7B
秘钥:http://www.it399.com
没有使用填充向量iv
AES解密异常Given final block not properly padded
javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:966)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:824)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:436)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
原因: 解密的时候直接对输入的16进制值 1243CFEBD819AA6B1C717DE870459F7B 取getBytes了,这样获取到的字节数组长度是16,不能直接这样操作。
inputValue.getBytes(AESUtil.CHARSET)
需要将16进制转字节数组,这样获取到的内容是32位,而且和之前直接获取到的字节数组不一样。
TypeConvert.hexStringToBytes(inputValue)
16进制转字节数组方法
/**
* Convert hex string to byte[]
*
* @param hexString the hex string
* @return byte[]
*/
public static byte[] hexStringToBytes(String hexString) {
if (hexString == null || hexString.equals("")) {
return null;
}
hexString = hexString.toUpperCase();
int length = hexString.length() / 2;
char[] hexChars = hexString.toCharArray();
byte[] d = new byte[length];
for (int i = 0; i < length; i++) {
int pos = i * 2;
d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
}
return d;
}
这样解密之后的字符串是 在线助手 正常!!
还有一种情况是输入的字符串不正常不能解密!
相关文章
AES 128/192/256位CBC/CFB/ECB/OFB/PCBC加密解密
http://www.it399.com/blog/web/201805211243
AES 128/192/256位CBC/CFB/ECB/OFB/PCBC在线加密解密|在线工具|在线助手|在线生成|在线制作
AES解密异常Given final block not properly padded
http://www.it399.com/blog/web/201805211406
本文同步发布在 在线助手博客|在线助手|在线工具|在线生成|在线制作 ,转载请注明来自 在线助手博客 频道【AES解密异常Given final block not properly padded】,原文链接:**http://www.it399.com/blog/web/201805211406**
以上是关于AES解密异常Given final block not properly padded-在线助手博客的主要内容,如果未能解决你的问题,请参考以下文章
“Given final block not properly padded. Such issues can arise if a bad key is used during“错误解决
“Given final block not properly padded. Such issues can arise if a bad key is used during“错误解决
java 3DES解密时, 解密的时候报错: javax.crypto.BadPaddingException: Given final block not properly
Java 之 Given final block not properly padded
javax.crypto.BadPaddingException: Given final block not properly padded
记一次文件编码出现的BUG javax.crypto.BadPaddingException: Given final block not properly padded