Java密钥工具生成证书请求不工作

Java密钥工具生成证书请求不工作,java,keytool,Java,Keytool,我正在尝试使用java生成认证请求,使用keytool。下面是我用来生成crs文件的代码: String generateCertificationRequest = "keytool –certreq –alias keypair –keyalg RSA –file src/main/resources/client.csr " + "–keystore src/main/resources/newKeyStoreFileName.

我正在尝试使用java生成认证请求,使用keytool。下面是我用来生成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.
密钥对被生成到jks文件中。

您的破折号实际上是。如果我直接复制:

$ echo "–certreq" | xxd
00000000: e280 9363 6572 7472 6571 0a              ...certreq.
而不是我自己打印出来:

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

所以只是复制/粘贴错误;也许无论你从哪里抄袭,都会像文字处理器或博客软件一样,试图美化文字。试着把它打印出来而不是抄写。

谢谢,你说得对。但现在我有另一个问题:
keytool错误:java.lang.Exception:别名不存在
。Csr文件已创建,但为空。如果没有新的可复制示例,很难知道存在什么问题。也许可以发布一个新问题?从表面上看,异常看起来不言自明,即您提供的密钥库中没有名为“keypair”的别名。
$ echo "-certreq" | xxd
00000000: 2d63 6572 7472 6571 0a                   -certreq.