仅供参考,测试使用.
1.通过JDK生成一个SSL证书
步骤:cmd中
命令:keytool -genkey -alias 证书名称 -keyalg RSA
-keystore d:\keystore.jks
-dname "CN=公开名称, OU=单位名称, O=组织名称, L=SH, ST=SH, C=CN"
-keypass key密码 -storepass 存储密码
-validity 有效天数
2.开始创建:keystore 文件
执行 keytool -genkey -alias tomcat -keyalg RSA 如下:
loiane:bin loiane$ keytool -genkey -alias tomcat -keyalg RSA
Enter keystore password: password
Re-enter new password: password
What is your first and last name?
[Unknown]: Loiane Groner
What is the name of your organizational unit?
[Unknown]: home
What is the name of your organization?
[Unknown]: home
What is the name of your City or Locality?
[Unknown]: Sao Paulo
What is the name of your State or Province?
[Unknown]: SP
What is the two-letter country code for this unit?
[Unknown]: BR
Is CN=Loiane Groner, OU=home, O=home, L=Sao Paulo, ST=SP, C=BR correct?
[no]: y
Enter key password for
(RETURN if same as keystore password): password
Re-enter new password: password
说明:这个tomcat密码和密钥库的密码最好弄成一样的,要不然在tomcat配置完server.xml之后有可能会导致启动失败
这样就在用户的主目录下创建了一个 .keystore 文件
3.配置 Tomcat 以使用 keystore 文件
打开 server.xml 找到下面被注释的这段
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
干掉注释,并将内容改为
<Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
disableUploadTimeout="true" enableLookups="false" maxThreads="25"
port="8443" keystorePass="password"
protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
secure="true" sslProtocol="TLS" />
4. 测试
启动 Tomcat 并访问 https://localhost:8443. 你将看到 Tomcat 默认的首页。
5.注:
虽然 JDK 的 keytool 工具也可以免费制作自签名的证书,但这只能用在练习或者测试中,因为如果数字证书颁布商不在浏览器的信任列表中,是会给用户弹出警告框的。
向 CA 提交域名及公司信息申请数字证书就可以了。当然了,数字证书的申请需要花费年费的,一年 4000 到 20000 元不等。
参考:
www.cnblogs.com/moon521/p/5948058.html
http://blog.csdn.net/tuoxinquyu/article/details/78364980?locationNum=9&fps=1
http://blog.51cto.com/wakan/21600
感谢分享。!
java中如何 把http变为https:
最新推荐文章于 2024-04-17 01:15:47 发布