如何通过 Java keytool 命令行界面生成 x.509 证书

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16851903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 00:10:22  来源:igfitidea点击:

How to generate x.509 certificate by the Java keytool command-line interface

javaresteasybouncycastle

提问by Amit Sharma

I am using RESTEasy encryption. For that I have to generate x.509 certificate by the Java 'keytool' command-line interface.

我正在使用 RESTEasy 加密。为此,我必须通过 Java 'keytool' 命令行界面生成 x.509 证书。

Please help me

请帮我

Thank you

谢谢

回答by Raza

This is the command to generate self signed certificates. All in one line

这是生成自签名证书的命令。全部在一条线上

keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks 
        -storepass password -validity 360 -keysize 2048

When you run this command, it will ask you for the details of the signatory. These will be the details of your organization. Provide all the details and it will create a new self signed certificate in keystore keystorefor you.

当您运行此命令时,它会询问您签名者的详细信息。这些将是您组织的详细信息。提供所有详细信息,它将在密钥库中keystore为您创建一个新的自签名证书。

NOTE:When it ask for your first and last name, give the domain name of the server which will be the entry point for your users. i.e. www.myserver.com

注意:当它询问您的名字和姓氏时,请提供服务器的域名,这将是您用户的入口点。即 www.myserver.com

If you already have a keystore then you can use your existing keystore to add new certificate otherwise this command will create the keystore keystore.jkswith the passwordand add the certificate to the new keystore. Note that if you already have a keystore then you need to provide the password of the existing keystore in -storepassparameter of this command.

如果你已经有一个密钥,那么你可以使用现有的密钥库中添加新的证书,否则此命令将创建密钥库keystore.jkspassword和证书添加到新的密钥库。请注意,如果您已经有一个密钥库,那么您需要在-storepass此命令的参数中提供现有密钥库的密码。

For more details, see the keytool man page: http://docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/keytool.html

有关更多详细信息,请参阅 keytool 手册页:http: //docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/keytool.html

Here you will find details of all the available options you can use with the keytool command.

在这里,您将找到可与 keytool 命令一起使用的所有可用选项的详细信息。