进行 SSLSocketServer 的最简单方法(运行时生成证书)
我想要一种简单的方法来创建 SSLServerSocket。我希望在运行时生成并使用自签名证书,因为数据需要受到保护,但它非常非常安全并不是非常重要。
我找到了有关制作 SSLServerSocket 的教程,但他们假设您有正确的证书。
伪代码、代码示例和简单的段落都是可以接受的答案。
I want a simple way to create a SSLServerSocket. I would like for a self-signed certificate to be generated and used at runtime because the data needs to be protected, but it isn't super important that it is very, very secure.
I found tutorials on making an SSLServerSocket but they assume that you had a proper certificate.
Psuedo-code, code examples and a simple paragraph are all acceptable answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法可能是调用外部程序。
openssl
是用于许多加密事物的出色工具...制作自签名证书:您可以使用
Runtime.exec()
或使用运行此类生成流程构建器。
The easiest way to do it may be invoking an external program.
openssl
is a great tool for many encryption things... Make a self signed cert with:You could run such generation with
Runtime.exec()
or using aProcessBuilder
.通常,如果自签名证书是在服务器每次运行时生成的,则它根本没有任何意义。最好创建一次自签名证书(例如在服务器设置期间),仅此而已。
对于用于保护通信的自签名证书有很好的描述和讨论在此 StackOverflow 主题中。请也阅读它,因为它也解决了您的问题。
Normally self-signed certificate has no sense at all if it's generated on each run of the server. It's better to create a self-signed certificate once (during server setup, for example) and that's all.
There's a good description and discussion of self-signed certificates for securing communication in this StackOverflow topic. Please read it as well, as it addresses your question too.