java - 在 Java 代码中使用自己的 keystore

标签 java tomcat keystore keytool private-key

我想使用 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/

相关文章:

java - 公钥验证总是返回 "Signature does not match"

ssl - 将证书导入为 PrivateKeyEntry

java - 如何修复 faSTLane 错误 : Keystore file 'keystore.jks' not found for signing config 'externalOverride' . ?

java - 列表过滤器<List<String>>

tomcat - 连接 Websphere MQ 的 tomcat 中的多个 Web 应用程序

tomcat - Grails 2.5.0 在部署到 tomcat 时不使用我的 lib/jars

php - 安装tomcat 8后Nginx 502 Bad Gateway错误

java - 更新 Set 中的对象

java - 解决 javax.net.ssl.SSLHandshakeException : sun. security.validator.ValidatorException : PKIX path building failed Error?

java - 将对象初始化为 null 还是 new?