I use this small snippet to store a KeyPair in Android's keystore :
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null);
Certificate[] cert = new Certificate[1];
cert[0] = getCertificate(kp);
ks.setKeyEntry(PRIVATE_KEY_TAG, kp.getPrivate(), null, cert);
ks.setKeyEntry(PUBLIC_KEY_TAG, kp.getPublic(), null, cert);
But when i fetch a key from KeyStore, with ks.getKey(PUBLIC_KEY_TAG, null).getEncoded()
, i get this exception :
Attempt to invoke interface method Key.getEncoded() on a null object
And when i try to encrypt a String through a Cipher, i get a :
Unknow key type passed to RSA
Any idea on why this KeyStore is causing problems ? Thanks.