JiboOne
JiboOne

Reputation: 1548

Using own keystore in java code

I want to use keystore to save a private key. I use this private key to encrypt datasource password. I generated myfile.keystore file with keytool and added the following configuration in Tomact server.xml file.

<Connector
protocol="HTTP/1.1"
port="8443" maxThreads="200"
scheme="https" secure="true" SSLEnabled="true"
keystoreFile="myfile.keystore" keystorePass="password"
clientAuth="false" sslProtocol="TLS"/>

How can I read this private key to use in Java code?

Upvotes: 1

Views: 841

Answers (1)

poussma
poussma

Reputation: 7321

The bit of XML configuration you sent us is only to configure the SSL for the tomcat server. It has nothing to do with the storage / reading of a private key for another purpose.

Here is a bit of code to load and initialize the key store.

FileInputStream is = new FileInputStream("myfile.keystore");

KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(is, "password".toCharArray());
Key key = keystore.getKey("my-alias", "password".toCharArray());

HIH

Upvotes: 1

Related Questions