【发布时间】:2016-09-29 22:41:25
【问题描述】:
我正在使用Qlassified library,但在 android 6.0 和 6.0.1 上出现以下异常:
java.lang.ClassCastException: android.security.keystore.AndroidKeyStoreECPublicKey cannot be cast to java.security.interfaces.RSAPublicKey
具体来说,当数据在此代码块内被加密时会发生这种情况:
final KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) keyStoreInstance.getEntry(alias, null);
final RSAPublicKey publicKey = (RSAPublicKey) privateKeyEntry.getCertificate().getPublicKey(); // error
byte[] dataBytes = input.getBytes(CHARSET);
Cipher cipher = Cipher.getInstance(ALGORITHM, ANDROID_MODE);
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return Base64.encodeToString(cipher.doFinal(dataBytes), BASE64_MODE);
有什么想法吗?
【问题讨论】:
-
使用带有 RSA 公钥的证书?
标签: java android cryptography android-6.0-marshmallow java-security