What about the AES decryption exception Given final block not properly padded
This article mainly shows you the "AES decryption abnormal Given final block not properly padded how to do", the content is easy to understand, clear, hope to help you solve the doubt, the following let the editor lead you to study and learn "AES decryption abnormal Given final block not properly padded how to do" this article.
On-line encryption and decryption of AES 128Blue192 and256-bit CBC/CFB/ECB/OFB/PCBC
Decrypted content: 1243CFEBD819AA6B1C717DE870459F7B
Secret key: http://www.it399.com
No fill vector iv is used
AES decryption exception 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)
Reason: decryption directly to the input hexadecimal value: 1243CFEBD819AA6B1C717DE870459F7B took getBytes, so the length of the byte array obtained is 16, can not be operated directly.
InputValue.getBytes (AESUtil.CHARSET)
You need to convert the hexadecimal to-byte array so that the content is 32 bits, and it is different from the byte array directly obtained before.
TypeConvert.hexStringToBytes (inputValue)
Hexadecimal rotation byte array method
/ * *
* 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; iTunes +) {
Int pos = I * 2
D [I] = (byte) (charToByte (hexChars [pos]))