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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
这是由于AES的秘钥写错了,规定是16位秘钥,写成了18位的秘钥。
2、解决方法
将AES秘钥改成规定的16位即可。