I'm trying to store a keypair into Android's keystore. So far, i have this test code :
KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
keygen.initialize(2048);
KeyPair keypair = keygen.generateKeyPair();
PrivateKey priv = keypair.getPrivate();
PublicKey pub = keypair.getPublic();
String passwd = "Insert some strong password here.";
Certificate[] certChain = new Certificate[1];
certChain[0] = generateCertificate(keypair);
ks.setKeyEntry("test", priv, passwd.toCharArray(), certChain);
The generateCertificate
method is using Bouncy Castle library.
When i run this code, i get a java.security.KeyStoreException: entries cannot be protected with passwords
Which is stange, since setKeyEntry
do have a password argument.
How can i get rid of this ? And is using a strong-string password stored in app's source code safe ?
Thanks.