Ich folge diesem Tutorial: How to use the Android Keystore to store passwords and other sensitive information. Es hängt (locker) mit der Google Sample App zusammen: BasicAndroidKeyStore.Crash Casting AndroidKeyStoreRSAPrivateKey zu RSAPrivateKey
Ich kann meine Daten mit dem öffentlichen Schlüssel verschlüsseln, und ich kann auf Geräten mit Lollipop entschlüsseln. Allerdings habe ich ein Nexus 6 läuft Eibisch und diese stürzt den Fehler geben:
java.lang.RuntimeException: Unable to create application com.android.test: java.lang.ClassCastException: android.security.keystore.AndroidKeyStoreRSAPrivateKey cannot be cast to java.security.interfaces.RSAPrivateKey
Hier ist der Code, stürzt auf:
KeyStore.Entry entry;
//Get Android KeyStore
ks = KeyStore.getInstance(KeystoreHelper.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
// Weird artifact of Java API. If you don't have an InputStream to load, you still need to call "load", or it'll crash.
ks.load(null);
// Load the key pair from the Android Key Store
entry = ks.getEntry(mAlias, null);
KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) entry;
//ERROR OCCURS HERE::
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) privateKeyEntry.getPrivateKey();
Cipher output = Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL");
output.init(Cipher.DECRYPT_MODE, rsaPrivateKey);
Ich bin nur ungern dies einem Android M Kuriosität to put down weil ich keinen Grund sehe, warum sich die Java-Crypto-Bibliotheken geändert hätten. Wenn die M-Version kommt und unsere App sofort auf M stürzt, werde ich in großen Schwierigkeiten sein.
Ich mache etwas falsch? Der Fehler sagt ganz konkret, dass Sie nicht nach RSAPrivateKey umwandeln können, also weiß jemand einen besseren Weg, den RSAPrivateKey aus dem Eintrag zu bekommen?
Vielen vielen Dank.
jetzt offen auf AOSP: [Ausgabe 205.450: Crash Casting AndroidKeyStoreRSAPrivateKey zu RSAPrivateKey] (https: // Code .google.com/p/android/issues/detail? id = 205450). – jww
Dies funktionierte nicht für mich auf Android N Vorschau 4 – resp78
diese Lösung funktioniert auf Lollipop. Aber auf Marshmallow wirft es: java.security.InvalidKeyException: Benötigen RSA privaten oder öffentlichen Schlüssel – deviant