Security.addProvider(new BouncyCastleProvider());
}
/* Generate a root and a normal certificate for this sample */
CertificateGenerator certificateGenerator = new CertificateGenerator();
RootCertificateVO rootCertificateInfo = certificateGenerator.createRootCertificate();
CertificateVO certificateContainer = certificateGenerator.createNormalizeCertificate2(rootCertificateInfo);
/*
* Create a keystore of type "JKS" using the "SUN" security provider
* because BouncyCastle do not support this type of keystore and
* then store the normal certificate private key into it
*/
System.out.printf("Create the keystore to the temporary file '%s'\n", keystoreTemporaryStorageFile.getAbsolutePath());
// --Initialize the keystore in order to set the keystore access
// password
KeyStore keyStoreForWrite = KeyStore.getInstance("JKS", Security.getProvider("SUN"));
keyStoreForWrite.load(null, KEYSTORE_ACCESS_PASSWORD.toCharArray());
// --Create a certificates array representing the normal certificate
// identification/validation chain
Certificate[] validationChain = { rootCertificateInfo.getRootCertificate(), certificateContainer.getCertificate() };
// --Save the normal certificate private key in the keystore
System.out.printf("Save the normal certificate private key below into it :\n%s\n", certificateContainer.getCertificatePrivateKey());
keyStoreForWrite.setKeyEntry(NORMAL_CERTIFICATE_PRIVATEKEY_IDENTIFICATION_ALIAS, certificateContainer.getCertificatePrivateKey(), NORMAL_CERTIFICATE_PRIVATEKEY_ACCESS_PASSWORD.toCharArray(), validationChain);
// --Save the keystore to a temporary file used for this sample
keyStoreForWrite.store(keystoreTemporaryStorageFileOS, KEYSTORE_ACCESS_PASSWORD.toCharArray());