javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
时间: 2023-11-09 22:56:52 浏览: 96
javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher是AES加密解密的报错异常。这个异常的意思是在使用AES解密时,解密的字符串的长度必须是8的倍数。通常,这种异常是由于解密的数据长度不正确导致的。
可能的原因是在解密过程中,传入的密文长度不是8的倍数。解决这个问题的方法是确保在解密之前,对密文进行正确的填充操作,使其长度为8的倍数。常用的填充方式包括PKCS5Padding和PKCS7Padding。
相关问题
java.lang.RuntimeException: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
引用中的错误提示"javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher"是在解密过程中出现的异常。这个异常的意思是解密的输入长度必须是8的倍数才能使用填充模式进行解密。同样的,引用中的异常提示"javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher"是在AES解密过程中出现的异常。这个异常的意思是解密的输入长度必须是16的倍数才能使用填充模式进行解密。而引用中的异常提示"java.lang.RuntimeException: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher"也是在解密过程中出现的异常,意思与前两个异常相同,都是解密的输入长度必须是16的倍数才能使用填充模式进行解密。所以,解决这个问题的方法就是确保解密的输入长度是符合要求的,即是8的倍数或是16的倍数。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padd](https://blog.csdn.net/weixin_45915335/article/details/124152930)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with pad](https://blog.csdn.net/qq_30624649/article/details/114937740)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [java javax.crypto.IllegalBlockSizeException: Data must not be longer than 245 bytes](https://blog.csdn.net/weixin_38081382/article/details/125485124)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
报错javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher 的解决方法
引用中提到,当使用AES解密时,报错javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher的意思是解密字符串的数组长度必须是16的倍数。所以解决这个问题的方法就是确保传入解密方法的字符串长度是16的倍数。你可以在加密之前,将原始字符串进行填充,使其长度符合要求。在解密之前,也需要确保解密字符串的长度是16的倍数。具体的实现方法可以参考代码中的示例中的相关部分。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* [javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padd](https://blog.csdn.net/weixin_45915335/article/details/124152930)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
- *2* [javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with pad](https://blog.csdn.net/qq_30624649/article/details/114937740)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
- *3* [java AES 加密,报javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when ...](https://blog.csdn.net/qq_36205206/article/details/119993785)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
[ .reference_list ]