如何从 Java 生成、签名和导入 SSL 证书
可能的重复:
使用 Java 生成证书、公钥和私钥
我需要在运行时生成自签名证书,对其进行签名并导入到 Java 密钥库。我可以通过以下方式从命令行使用“keytool”和“openssl”来执行此操作:
keytool -import -alias root -keystore keystore.txt -file cacert.pem
keytool -genkey -keyalg RSA -keysize 1024 -alias www.cia.gov -keystore keystore.txt
keytool -keystore keystore.txt -certreq -alias www.cia.gov -file req.pem
openssl x509 -req -days 3650 -in req.pem -CA cacert.pem -CAkey cakey.pem -CAcreateserial -out reqsigned.pem
keytool -import -alias www.cia.gov -keystore keystore.txt -trustcacerts -file reqsigned.pem
当然,我可以使用 keytool 和 openssl 二进制文件发送我的应用程序,并从 Java 执行上述命令,但我正在寻找一个更清洁的程序方法允许我使用纯 Java 完成上述所有操作。
我可以使用任何库吗?
Possible Duplicate:
Generate certificates, public and private keys with Java
I need to generate a self signed certificates at run time, sign them and import to the Java keystore. I can do this using "keytool" and "openssl" from command line in the following way:
keytool -import -alias root -keystore keystore.txt -file cacert.pem
keytool -genkey -keyalg RSA -keysize 1024 -alias www.cia.gov -keystore keystore.txt
keytool -keystore keystore.txt -certreq -alias www.cia.gov -file req.pem
openssl x509 -req -days 3650 -in req.pem -CA cacert.pem -CAkey cakey.pem -CAcreateserial -out reqsigned.pem
keytool -import -alias www.cia.gov -keystore keystore.txt -trustcacerts -file reqsigned.pem
I can, of course, ship my application with keytool and openssl binaries and execute the above commands from Java, but I'm looking for a cleaner approach which would allow me to do all of the above using pure Java.
Any libraries I can use ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 BouncyCastle 生成证书。我相信它还允许您将它们导入 Java 密钥库。
另外,您的问题似乎与这个问题非常相似。
Use BouncyCastle to generate certificates. I believe it also allows you to import them to Java keystore.
Also your question seems to be very similar to this one.