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 paddedjava

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,不能直接這樣操做web

inputValue.getBytes(AESUtil.CHARSET)

須要將16進制轉字節數組,這樣獲取到的內容是32位,並且和以前直接獲取到的字節數組不同。數組

TypeConvert.hexStringToBytes(inputValue)

16進制轉字節數組方法ide

/**
     * 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在線加密解密|在線工具|在線助手|在線生成|在線製做 http://www.it399.com/aes #####AES解密異常Given final block not properly padded http://www.it399.com/blog/web/201805211406code

本文同步發佈在 在線助手博客|在線助手|在線工具|在線生成|在線製做轉載請註明來自 在線助手博客 頻道【AES解密異常Given final block not properly padded】,原文連接:http://www.it399.com/blog/web/201805211406blog

相關文章
相關標籤/搜索