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' characters (U+2013)。如果我直接复制:
$ echo "–certreq" | xxd
00000000: e280 9363 6572 7472 6571 0a ...certreq.
与我自己输入相反:
$ echo "-certreq" | xxd
00000000: 2d63 6572 7472 6571 0a -certreq.
所以只是一个 copy/paste 错误;可能无论你从哪里复制,都太过努力地美化文本,就像文字处理器或博客软件可能做的那样。尝试将其键入而不是复制。
我正在尝试使用 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.
所以只是一个 copy/paste 错误;可能无论你从哪里复制,都太过努力地美化文本,就像文字处理器或博客软件可能做的那样。尝试将其键入而不是复制。