我想使用 keystore 来保存私钥。我使用这个私钥来加密数据源密码。 我使用 keytool 生成了 myfile.keystore 文件,并在 Tomact server.xml 文件中添加了以下配置。
<Connector
protocol="HTTP/1.1"
port="8443" maxThreads="200"
scheme="https" secure="true" SSLEnabled="true"
keystoreFile="myfile.keystore" keystorePass="password"
clientAuth="false" sslProtocol="TLS"/>
如何读取此私钥以在 Java 代码中使用?
最佳答案
您发送给我们的 XML 配置位只是为 tomcat 服务器配置 SSL。与出于其他目的存储/读取私钥无关。
这里有一些代码来加载和初始化 keystore 。
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());
高
关于java - 在 Java 代码中使用自己的 keystore ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14315154/