Keytool错误:java.lang.Exception:无法解析输入

时间:2013-07-18 13:38:04

标签: ssl

这个问题可能重复,但我无法得到解决方案, 我尝试使用以下命令创建SSL证书,

C:\Program Files\Java\jdk1.6.0_05\bin>keytool -genkey -alias tomcat -keyalg RSA
-keystore E:\key
Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:  Raghu
What is the name of your organizational unit?
  [Unknown]:  BFS
What is the name of your organization?
  [Unknown]:  iGate
What is the name of your City or Locality?
  [Unknown]:  Bang
What is the name of your State or Province?
  [Unknown]:  KA
What is the two-letter country code for this unit?
  [Unknown]:  IN
Is CN=Raghu, OU=BFS, O=iGate, L=Bang, ST=KA, C=IN correct?
  [no]:  y

Enter key password for <tomcat>
        (RETURN if same as keystore password):
Re-enter new password:

我已尝试使用以下命令获取证书请求

C:\Program Files\Java\jdk1.6.0_05\bin>keytool -certreq -v -alias tomcat -keyalg
RSA -keystore E:\key
Enter keystore password:

在命令提示符下得到以下响应

**-----BEGIN NEW CERTIFICATE REQUEST----- MIIBlzCCAQACAQAwVzELMAkGA1UEBhMCSU4xCzAJBgNVBAgTAktBMQ0wCwYDVQQHEwRCYW5nMQ4w
DAYDVQQKEwVpR2F0ZTEMMAoGA1UECxMDQkZTMQ4wDAYDVQQDEwVSYWdodTCBnzANBgkqhkiG9w0B
AQEFAAOBjQAwgYkCgYEA0Aoxz2V/Cqs00d7d4iVysIcfMxXDA4ydD5+AY2Q2hPqIOAbfrz0HiSjZ
JwKV0/g7P/oWPU9fCFYnLXAynusbaAtw5xIolMNqj9gtxmD1BzrwxcVIX3oWY0LzO768TMY3Szjp
tS64z5q1KSTYqeZww0f11N2JssjtMch8gw50FIcCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA4GBAK1v
sE0BNxGrGKNBXhYuSdgwF14ZnELtjWBzDJDzbzgJbK6RJlOEstKxdStR2fq7iv0ow+Df7TnVWidm
+0PRLuhtr3DMZVX2acNQY4c4ynKWgLyBV2lAXbYfgZdzQr3ClY+40lkbmHQaMxZcxz2q7u8Np6sH
n0iytY6U0CqJpRcB
----END NEW CERTIFICATE REQUEST-----**

我保存在cert.txt文件中并验证证书回复

 C:\Program Files\Java\jdk1.6.0_05\bin>keytool -printcert -file E:\cert.txt

**keytool error: java.lang.Exception: Failed to parse input**

我收到了上述错误。请建议同样的。

2 个答案:

答案 0 :(得分:4)

您对证书证书请求感到困惑。

当您使用-certreq时,您正在生成证书申请(CSR),您应该将其发送给您的CA,CA会向您发送证书作为回报。然后,您就可以将该证书导入到您的密钥库中,而不是它已经拥有的私钥(并且是使用-genkey生成的。

-printcert用于打印证书,而不是证书请求(BEGIN NEW CERTIFICATE REQUEST)。

答案 1 :(得分:1)

我认为你错过了造成这个问题的一步。

keytool -exportcert -rfc -keystore D:\key -file D:\cert.crt 

请检查此link