javax.crypto.IllegalBlockSizeException: Input length not multiple of 16 bytes
时间: 2024-06-13 08:05:08 浏览: 24
这个异常是因为在使用AES解密时,解密的字符串的数组长度不是16的倍数所导致的。在AES加密中,加密的数据长度必须是16的倍数,如果不是,则需要进行填充。而在解密时,如果解密的数据长度不是16的倍数,则会抛出该异常。为了解决这个问题,可以在加密时使用填充方式,例如PKCS5Padding,来保证加密后的数据长度是16的倍数。同时,在解密时也需要使用相同的填充方式来解密。
相关问题
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 ]