Android 9 – KeyStore exception android.os.ServiceSpecificException

Finally I found a solution. It looks like since Android P (KeyStore.PrivateKeyEntry) keyStore.getEntry(“alias”, null) is not a proper way to get private key. I was able to get rid of this warning by accessing private/public key this way KeyStore keyStore = KeyStore.getInstance(“AndroidKeyStore”); keyStore.load(null); PrivateKey privateKey = (PrivateKey) keyStore.getKey(“alias”, null); PublicKey publicKey = keyStore.getCertificate(“alias”).getPublicKey();

Android Keystore Error “could not generate key in keystore”

public class EncryptionApi18AndAbove{ private Context context; private KeyStore keyStore; private static String alias = “alias”; public EncryptionApi18AndAbove(Context context) { this.context = context; try { keyStore = KeyStore.getInstance(“AndroidKeyStore”); keyStore.load(null); } catch (Exception e) { // bla bla } } private String createNewKeys(String alias, Context context) { try { if (!keyStore.containsAlias(alias)) { Calendar start = Calendar.getInstance(); Calendar … Read more

Android Fingerprint API Encryption and Decryption

I found the final piece of the puzzle on the Android Issue Tracker, another known bug causes the unrestricted PublicKey to be incompatible with the Cipher when using OAEP. The work around is to add a new OAEPParameterSpec to the Cipher upon initialization: OAEPParameterSpec spec = new OAEPParameterSpec( “SHA-256”, “MGF1”, MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT); mCipher.init(opmode, unrestricted, spec); … Read more

How Can I Use the Android KeyStore to securely store arbitrary strings?

I started with the premise that I could use AndroidKeyStore to secure arbitrary blobs of data, and call them “keys”. However, the deeper I delved into this, the clearer it became that the KeyStore API is deeply entangled with Security-related objects: Certificates, KeySpecs, Providers, etc. It’s not designed to store arbitrary data, and I don’t … Read more

Warning: Different store and key passwords not supported for PKCS12 KeyStores. Ignoring user-specified -keypass value. in Android Studio

This is a known issue with Android Studio 4.2. It runs on JDK11 which has this limitation. Google’s own documentation on app signing states that the key password “should be different from the password you chose for your keystore” so I’m guessing they intend to fix this at some point.