error “java.security.cert.CertificateException: No name matching localhost found”

使用tomcat开启https 需要使用keytool命令来生产一个证书。
详细命令如下:

keytool -genkey -alias serverkey -keypass nosecret -keyalg RSA -sigalg SHA1withRSA -keystore server.keystore -storepass nostoresecret

过程中如下:

What is your first and last name?
[Unknown]: localhost(这里输入域名 不是名称)
What is the name of your organizational unit?
[Unknown]: globinch ws
What is the name of your organization?
[Unknown]: globinch
What is the name of your City or Locality?
[Unknown]: Bangalore
What is the name of your State or Province?
[Unknown]: KAR
What is the two-letter country code for this unit?
[Unknown]: IN
Is CN=localhost, OU=globinch ws, O=globinch, L=Bangalore, ST=KAR, C=IN correct?
[no]: yes

如果上面的地方没有输入域名 在使用时会报:

Caused by: javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: No name matching localhost found
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1611)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)

这样的错误

发表评论

电子邮件地址不会被公开。 必填项已用*标注