I receive from a web service(made by myself) an RSA PrivateKey PKCS#8 encoded in a base 64 String. My Android app must save this key somewhere into the phone securely.
In KeyStore
the private keys must be stored along with a certificate (even a fake self-signed certificate). To store your key in the AndroidKeyStore
you should follow these steps:
PrivateKey
instance Now you can add your key to the keystore.
PrivateKey myKey = getKey();
X509Certificate certificate = getCertificate();
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
keystore.setKeyEntry("anAlias", myKey, null, new Certificate[] { certificate });