阅读背景:

JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher

来源:互联网 

加密代码

 

        /**解密
         * @param content  待解密内容
         * @param password 解密密钥
         * @return
         */
        public static byte[] decrypt(byte[] content, String password) {
                try {
                         KeyGenerator kgen = KeyGenerator.getInstance("AES");
                         kgen.init(128, new SecureRandom(password.getBytes()));
                         SecretKey secretKey = kgen.generateKey();
                         byte[] enCodeFormat = secretKey.getEncoded();
                         SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");            
                         Cipher cipher = Cipher.getInstance("AES");// 创建密码器
                        cipher.init(Cipher.DECRYPT_MODE, key);// 初始化
                        byte[] result = cipher.doFinal(content);
                        return result; // 加密
                } catch (NoSuchAlgorithmException e) {
                        e.printStackTrace();
                } catch (NoSuchPaddingException e) {
                        e.printStackTrace();
                } catch (InvalidKeyException e) {
                        e.printStackTrace();
                } catch (IllegalBlockSizeException e) {
                        e.printStackTrace();
                } catch (BadPaddingException e) {
                        e.printStackTrace();
                }
                return null;
        }
        /**解密
         * @param 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: