繁体   English   中英

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

[英]Java KeyTool generate certificate request not working

我正在尝试使用 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' 字符 (U+2013) 如果我直接复制:

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

与我自己输入相反:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM