1

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! That's exactly what I was asking about :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.