Crash casting AndroidKeyStoreRSAPrivateKey to RSAPrivateKey

I managed to get this working by removing the Provider from Cipher.getInstance and not casting to a RSAprivateKey.

KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) entry;

Cipher output = Cipher.getInstance("RSA/ECB/PKCS1Padding");
output.init(Cipher.DECRYPT_MODE, privateKeyEntry.getPrivateKey());

I’m not 100% but I think the reason for this I believe is the change in marshmallow from OpenSSL to BoringSSL.
https://developer.android.com/preview/behavior-changes.html#behavior-apache-http-client

Anyway, the above worked for M and below.

Leave a Comment