I am trying to create a PKCS 12 (P12) file using Java (and BouncyCastle). For some reason my code is not adding my password to the key entry that I add to the p12 file.
The password for the p12 file itself works. However the password for a specific key entry is not added.
My code:
// open the file
fileName = "my_output.p12";
OutputStream outFile = new FileOutputStream (fileName);
// get privatekey and cert details ...
// ...
// initialize
// note: I have also tried: KeyStore.getInstance("PKCS12", "BC");
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(null, null);
// this line doesn't add my password "test_pass" !
keyStore.setKeyEntry("test_alias", myExistingPrivateKey, "key_pass".toCharArray(), myExistingCertChain);
// store keystore and close file
keyStore.store(outFile, "container_pass".toCharArray());
outFile.close();
Note the same code works fine when the container type is JKS instead of PKCS12