微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Java KeyTool 生成证书请求不起作用

如何解决Java KeyTool 生成证书请求不起作用

我正在尝试使用 keytool 使用 java 生成认证请求。这是我用来生成 crs 文件代码

String generateCertificationRequest = "keytool –certreq –alias keypair –keyalg RSA –file src/main/resources/client.csr "
                + "–keystore src/main/resources/newKeyStoreFileName.jks -storepass pass";

        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec(generateCertificationRequest);

未创建 Csr 文件,我收到此消息:

Illegal option:  –certreq
Key and Certificate Management Tool

Commands:

 -certreq            Generates a certificate request
 -changealias        Changes an entry's alias
 -delete             Deletes an entry
 -exportcert         Exports certificate
 -genkeypair         Generates a key pair
 -genseckey          Generates a secret key
 -gencert            Generates certificate from a certificate request
 -importcert         Imports a certificate or a certificate chain
 -importpass         Imports a password
 -importkeystore     Imports one or all entries from another keystore
 -keypasswd          Changes the key password of an entry
 -list               Lists entries in a keystore
 -printcert          Prints the content of a certificate
 -printcertreq       Prints the content of a certificate request
 -printcrl           Prints the content of a CRL file
 -storepasswd        Changes the store password of a keystore
 -showinfo           displays security-related information

Use "keytool -?,-h,or --help" for this help message
Use "keytool -command_name --help" for usage of command_name.
Use the -conf <url> option to specify a pre-configured options file.

同样的命令在 cmd 中起作用,并生成 csr 文件。在此命令之前,我使用以下代码生成密钥对:

String generateKeyPair = "keytool -genkey -alias keypair \r\n"
                + "    -keyalg RSA -keystore src/main/resources/newKeyStoreFileName.jks \r\n"
                + "    -dname \"CN=Mark Smith,OU=JavaSoft,O=Sun,L=Cupertino,S=California,C=US\" \r\n"
                + "    -storepass pass -keypass pass";
Process proc1 = rt.exec(generateKeyPair);

密钥对生成到 jks 文件中。

解决方法

你的破折号实际上是 'EN DASH' characters (U+2013)。如果我直接复制:

$ echo "–certreq" | xxd
00000000: e280 9363 6572 7472 6571 0a              ...certreq.

与我自己输入相反:

$ echo "-certreq" | xxd
00000000: 2d63 6572 7472 6571 0a                   -certreq.

所以只是一个复制/粘贴错误;可能无论你从哪里复制,都在努力美化文本,就像文字处理器或博客软件可能做的那样。尝试输入而不是复制。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。