【发布时间】:2018-02-12 19:45:33
【问题描述】:
我最近开始在设备中看到此错误。
java.security.InvalidKeyException: Only SecretKey is supported
at com.android.org.conscrypt.OpenSSLCipher.checkAndSetEncodedKey(OpenSSLCipher.java:436)
at com.android.org.conscrypt.OpenSSLCipher.engineInit(OpenSSLCipher.java:273)
at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2664)
at javax.crypto.Cipher.tryCombinations(Cipher.java:2575)
at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2480)
at javax.crypto.Cipher.chooseProvider(Cipher.java:567)
at javax.crypto.Cipher.init(Cipher.java:975)
at javax.crypto.Cipher.init(Cipher.java:910)
if (!(key instanceof SecretKey)) {
throw new InvalidKeyException("Only SecretKey is supported");
}
我总是像这样从商店获取我的 SecretKey:
SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null);
知道发生了什么吗?
【问题讨论】:
-
如果
key是null,就会发生这种情况。null instanceof T总是返回false。
标签: android security ssl encryption boringssl