关于AES加密报错 InvalidKeyException: Key length not 128/192/256 bits.

Exception in thread "main" cn.hutool.crypto.CryptoException: InvalidKeyException: Key length not 128/192/256 bits.
	at cn.hutool.crypto.symmetric.SymmetricCrypto.encrypt(SymmetricCrypto.java:209)
	at App2.main(App2.java:133)
Caused by: java.security.InvalidKeyException: Key length not 128/192/256 bits.
	at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineInit(Unknown Source)
	at javax.crypto.Cipher.init(Cipher.java:1249)
	at javax.crypto.Cipher.init(Cipher.java:1189)
	at cn.hutool.crypto.symmetric.SymmetricCrypto.encrypt(SymmetricCrypto.java:203)
	... 1 more

        byte[] bytes1 = "0123456789012345-".getBytes();
        AES aes1 = SecureUtil.aes(bytes1);
        String enc = aes1.encryptHex("hhh");
        System.out.println(enc);
        String dec =aes1.decryptStr(enc);
        System.out.println(dec);

秘钥改成16位字符串就好了

       byte[] bytes1 = "0123456789012345-".getBytes();

       byte[] bytes1 = "0123456789012345".getBytes();

你可能感兴趣的:(java,开发语言)