I read that there is problem with method KeyChain.getPrivateKey(Context,String) on Android 4.1 although on older versions it works. Does anybody has solution how to get private key on JellyBean?
Saw this Using Android 4.1 Keychain , but somehow could not get to work with my case.
Code that does not work on 4.1, but works great on older versions.
PrivateKey pk;
try {
pk = KeyChain.getPrivateKey(context,string);
byte[] pkByte = pk.getEncoded();
pkBase64 = new String(Base64.encode(pkByte, Base64.NO_WRAP));
}
Edited: Found out that if I do not change certificate alias(default hex-hex-hex) when adding it, then getPrivateKey returns null, but when I change alias to, for example, aaa method returns something, but still not the correct privatekey. (for example, returned private key with primeP =null primeQ =null. On Android 4.0.4 primeP and primeQ are not null values)