当前位置:   article > 正文

关于AES加密报错 InvalidKeyException: Key length not 128/192/256 bits._cn.hutool.crypto.cryptoexception: invalidkeyexcept

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

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

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

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/409051
推荐阅读
相关标签
  

闽ICP备14008679号