简体   繁体   English

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

[英]Java KeyTool generate certificate request not working

I'm trying to generate certification request with java, using keytool.我正在尝试使用 keytool 生成带有 java 的认证请求。 Here's code I'm using to generate crs file:这是我用来生成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 file is not created and I get this message:未创建 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.

The same command works in cmd and csr file is generated.相同的命令在 cmd 中工作,并生成 csr 文件。 Before this command I'm generating keypair using this code:在此命令之前,我使用以下代码生成密钥对:

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);

Keypair is generated into jks file.密钥对生成到 jks 文件中。

Your dashes are actually 'EN DASH' characters (U+2013) .您的破折号实际上是'EN DASH' 字符 (U+2013) If I copy directly:如果我直接复制:

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

As opposed to if I type it out myself:与我自己输入相反:

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

So just a copy/paste error;所以只是一个复制/粘贴错误; probably wherever you're copying from is trying too hard to prettify the text, like a word processor or blog software might do.可能无论您从哪里复制,都在努力美化文本,就像文字处理器或博客软件可能会做的那样。 Try typing it out instead of copying.尝试输入而不是复制。

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

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