Given final block not properly padded

获取Cipher对象的时候一定要写成

Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");

不要写成

Cipher cipher = Cipher.getInstance("DES");

否则解密的时候会报错:

Given final block not properly padded


原因是Cipher cipher = Cipher.getInstance("DES");与Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");等同,填充方式错误,加密的时候会得到16长度的字节数组。



转载地址:http://lhc1986.iteye.com/blog/1730477

你可能感兴趣的:(Given final block not properly padded)