我的Android进阶之旅------>解决AES加密报错:java.security.InvalidKeyException: Unsupported key size: 18 bytes

1、错误描述

今天使用AES进行加密时候,报错如下所示:


04-21 11:08:18.087 27501-27501/com.xtc.watch E/AESUtil.decryptAES:55: java.security.InvalidKeyException: Unsupported key size: 18 bytes
                                                                          at com.android.org.conscrypt.OpenSSLCipher$EVP_CIPHER$AES.checkSupportedKeySize(OpenSSLCipher.java:686)
                                                                          at com.android.org.conscrypt.OpenSSLCipher.checkAndSetEncodedKey(OpenSSLCipher.java:442)
                                                                          at com.android.org.conscrypt.OpenSSLCipher.engineInit(OpenSSLCipher.java:260)
                                                                          at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:612)
                                                                          at javax.crypto.Cipher.tryCombinations(Cipher.java:532)
                                                                          at javax.crypto.Cipher.getSpi(Cipher.java:437)
                                                                          at javax.crypto.Cipher.init(Cipher.java:815)
                                                                          at javax.crypto.Cipher.init(Cipher.java:774)
                                                                          at com.xtc.watch.util.AESUtil.decrypt(AESUtil.java:88)
                                                                          at com.xtc.watch.util.AESUtil.decryptAES(AESUtil.java:52)
                                                                          at com.xtc.watch.view.homepage.activity.HomePageActivity.verifyWeakPassword(HomePageActivity.java:364)
                                                                          at com.xtc.watch.view.homepage.activity.HomePageActivity.onCreate(HomePageActivity.java:356)
                                                                          at android.app.Activity.performCreate(Activity.java:6303)
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2374)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
                                                                          at android.app.ActivityThread.access$900(ActivityThread.java:153)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at android.os.Looper.loop(Looper.java:148)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5432)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:735)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)

我的Android进阶之旅------>解决AES加密报错:java.security.InvalidKeyException: Unsupported key size: 18 bytes

这是由于AES的秘钥写错了,规定是16位秘钥,写成了18位的秘钥。

2、解决方法

将AES秘钥改成规定的16位即可。

作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng

我的Android进阶之旅------>解决AES加密报错:java.security.InvalidKeyException: Unsupported key size: 18 bytes

上一篇:Jupyter 编写python代码实现代码自动补齐功能设置实例演示


下一篇:asp.net的session的模式