I'm trying to programmatically create a new keystore in Java. The following code:
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.setCertificateEntry("alias", cert);
throws a Uninitialized KeyStore exception.
To create a custom key store, you must specify an active AWS CloudHSM cluster that is not already associated with another key store. You also need to create a dedicated crypto user (CU) in the cluster's HSMs that AWS KMS can use to create and manage keys on your behalf.
By default, Java has a keystore file located at JAVA_HOME/jre/lib/security/cacerts.
You cannot create a keystore with a blank password with keytool since a while, but you can still do it programmatically.
Use the standard JDK keytool utility to generate and load a new key and a self-signed certificate. When prompted, supply the certificate and password information. Doing so protects the keystore file and the keys within in the file.
To create a new KeyStore in Java you first need to create the KeyStore file and then store it using the store(FileOutputStream, char[])
method:
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); char[] password = "some password".toCharArray(); ks.load(null, password); // Store away the keystore. FileOutputStream fos = new FileOutputStream("newKeyStoreFileName"); ks.store(fos, password); fos.close();
I hope this helps, you can see more info here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With