keytool command

keytool concept

  • keytool
    is a key and certificate management tool. It enables users to manage their own public/private key pairs and related certificates for self-authentication (through digital signatures) (users authenticate themselves to other users/services) or data integrity and authentication services. It also allows users to store the public keys of their communicating peers (in the form of certificates)

certificate

  • A certificate is a digitally signed statement from an entity (individual, company, etc.) that states that the public key (and other information) of some other entity has a certain specific value (see certificate). After the data is digitally signed, the integrity and authenticity of the data can be checked by verifying the signature! Integrity means that the data has not been modified or damaged, and authenticity means that the data does come from the entity that claims to have created the data and signed it.

  • keytool stores keys and certificates in a so-called keystore. The default key store implementation implements the key store as a file. It uses a password to protect the private key.
    The jarsigner tool uses the information in the key repository to generate or verify the digital signature of a Java archive (JAR) file (a JAR file packs class files, images, sounds, and/or other digital data in one file). jarsigner uses the certificate attached to the JAR file (included in the signature block file of the JAR file) to verify the digital signature of the JAR file, and then checks whether the public key of the certificate is "trustworthy", that is, whether it is included in the designated key repository in.

Keytool command usage

When executing the keytool command in the cmd console, you should go to the corresponding bin directory to execute the command

C:\Program Files\Java\jdk1.8.0_251\bin

Use the keeytool command to generate a pair of secret keys (example)

keytool -genkey 
                -dname "cn=Zhangsan, ou=xxx, o=xxx, c=xxx" //姓名、单位组织等相关信息
                -alias key             //别名key
                -keypass k123456       //设置存储在keystore中秘钥对的解码           
                -keystore D:\key.jks   //keystore的位置
                -storepass k123456     //打开keystore所需要的面
                -validity 1000         //有效时间此处为1000天
                -keyalg RSA            //指定产生秘钥算法
                -keysize 2048           //秘钥位大小
                -v                     //生成秘钥消息信息,根据个人情况可加可不加

Enter the above line of code in the command line to perform the operation. This display is for the convenience of everyone's understanding

Next is the keytool command

 keytool -help
 
 -certreq            生成证书请求
 -changealias        更改条目的别名
 -delete             删除条目
 -exportcert         导出证书
 -genkeypair         生成密钥对
 -genseckey          生成密钥
 -gencert            根据证书请求生成证书
 -importcert         导入证书或证书链
 -importpass         导入口令
 -importkeystore     从其他密钥库导入一个或所有条目
 -keypasswd          更改条目的密钥口令
 -list               列出密钥库中的条目
 -printcert          打印证书内容
 -printcertreq       打印证书请求的内容
 -printcrl           打印 CRL 文件的内容
 keytool -certreq -help(生成证书请求)
 
 -alias <alias>                  要处理的条目的别名
 -sigalg <sigalg>                签名算法名称
 -file <filename>                输出文件名
 -keypass <arg>                  密钥口令
 -keystore <keystore>            密钥库名称
 -dname <dname>                  唯一判别名
 -storepass <arg>                密钥库口令
 -storetype <storetype>          密钥库类型
 -providername <providername>    提供方名称
 -providerclass <providerclass>  提供方类名
 -providerarg <arg>              提供方参数
 -providerpath <pathlist>        提供方类路径
 -v                              详细输出
 -protected                      通过受保护的机制的口令
keytool -changealias -help(更改条目的别名)

 -alias <alias>                   要处理的条目的别名
 -destalias <destalias>           目标别名
 -keypass <arg>                   密钥口令
 -keystore <keystore>             密钥库名称
 -storepass <arg>                 密钥库口令
 -storetype <storetype>           密钥库类型
 -providername <providername>     提供方名称
 -providerclass <providerclass>   提供方类名
 -providerarg <arg>               提供方参数
 -providerpath <pathlist>         提供方类路径
 -v                               详细输出
 -protected                       通过受保护的机制的口令
keytool -delete -help(删除条目)

 -alias <alias>                  要处理的条目的别名
 -keystore <keystore>            密钥库名称
 -storepass <arg>                密钥库口令
 -storetype <storetype>          密钥库类型
 -providername <providername>    提供方名称
 -providerclass <providerclass>  提供方类名
 -providerarg <arg>              提供方参数
 -providerpath <pathlist>        提供方类路径
 -v                              详细输出
 -protected                      通过受保护的机制的口令
keytool -exportcert -help(导出证书)

 -rfc                            以 RFC 样式输出
 -alias <alias>                  要处理的条目的别名
 -file <filename>                输出文件名
 -keystore <keystore>            密钥库名称
 -storepass <arg>                密钥库口令
 -storetype <storetype>          密钥库类型
 -providername <providername>    提供方名称
 -providerclass <providerclass>  提供方类名
 -providerarg <arg>              提供方参数
 -providerpath <pathlist>        提供方类路径
 -v                              详细输出
 -protected                      通过受保护的机制的口令
keytool -genkeypair -help(生成秘钥对)

 -alias <alias>                  要处理的条目的别名
 -keyalg <keyalg>                密钥算法名称
 -keysize <keysize>              密钥位大小
 -sigalg <sigalg>                签名算法名称
 -destalias <destalias>          目标别名
 -dname <dname>                  唯一判别名
 -startdate <startdate>          证书有效期开始日期/时间
 -ext <value>                    X.509 扩展
 -validity <valDays>             有效天数
 -keypass <arg>                  密钥口令
 -keystore <keystore>            密钥库名称
 -storepass <arg>                密钥库口令
 -storetype <storetype>          密钥库类型
 -providername <providername>    提供方名称
 -providerclass <providerclass>  提供方类名
 -providerarg <arg>              提供方参数
 -providerpath <pathlist>        提供方类路径
 -v                              详细输出
 -protected                      通过受保护的机制的口令
keytool -genseckey -help(生成秘钥)

 -alias <alias>                  要处理的条目的别名
 -keypass <arg>                  密钥口令
 -keyalg <keyalg>                密钥算法名称
 -keysize <keysize>              密钥位大小
 -keystore <keystore>            密钥库名称
 -storepass <arg>                密钥库口令
 -storetype <storetype>          密钥库类型
 -providername <providername>    提供方名称
 -providerclass <providerclass>  提供方类名
 -providerarg <arg>              提供方参数
 -providerpath <pathlist>        提供方类路径
 -v                              详细输出
 -protected                      通过受保护的机制的口令
keytool -gencert -help(根据证书请求生成证书)

 -rfc                            以 RFC 样式输出
 -infile <filename>              输入文件名
 -outfile <filename>             输出文件名
 -alias <alias>                  要处理的条目的别名
 -sigalg <sigalg>                签名算法名称
 -dname <dname>                  唯一判别名
 -startdate <startdate>          证书有效期开始日期/时间
 -ext <value>                    X.509 扩展
 -validity <valDays>             有效天数
 -keypass <arg>                  密钥口令
 -keystore <keystore>            密钥库名称
 -storepass <arg>                密钥库口令
 -storetype <storetype>          密钥库类型
 -providername <providername>    提供方名称
 -providerclass <providerclass>  提供方类名
 -providerarg <arg>              提供方参数
 -providerpath <pathlist>        提供方类路径
 -v                              详细输出
 -protected                      通过受保护的机制的口令
keytool -importcert -help(导入证书或证书链)

 -noprompt                        不提示
 -trustcacerts                    信任来自 cacerts 的证书
 -protected                       通过受保护的机制的口令
 -alias <alias>                   要处理的条目的别名
 -file <filename>                 输入文件名
 -keypass <arg>                   密钥口令
 -keystore <keystore>             密钥库名称
 -storepass <arg>                 密钥库口令
 -storetype <storetype>           密钥库类型
 -providername <providername>     提供方名称
 -providerclass <providerclass>   提供方类名
 -providerarg <arg>               提供方参数
 -providerpath <pathlist>         提供方类路径
 -v                               详细输出
keytool -importpass -help(导入口令)

 -alias <alias>                  要处理的条目的别名
 -keypass <arg>                  密钥口令
 -keyalg <keyalg>                密钥算法名称
 -keysize <keysize>              密钥位大小
 -keystore <keystore>            密钥库名称
 -storepass <arg>                密钥库口令
 -storetype <storetype>          密钥库类型
 -providername <providername>    提供方名称
 -providerclass <providerclass>  提供方类名
 -providerarg <arg>              提供方参数
 -providerpath <pathlist>        提供方类路径
 -v                              详细输出
 -protected                      通过受保护的机制的口令
keytool -importkeystore -help(从其他秘钥库导入一个或所有条目)

 -srckeystore <srckeystore>             源密钥库名称
 -destkeystore <destkeystore>           目标密钥库名称
 -srcstoretype <srcstoretype>           源密钥库类型
 -deststoretype <deststoretype>         目标密钥库类型
 -srcstorepass <arg>                    源密钥库口令
 -deststorepass <arg>                   目标密钥库口令
 -srcprotected                          受保护的源密钥库口令
 -srcprovidername <srcprovidername>     源密钥库提供方名称
 -destprovidername <destprovidername>   目标密钥库提供方名称
 -srcalias <srcalias>                   源别名
 -destalias <destalias>                 目标别名
 -srckeypass <arg>                      源密钥口令
 -destkeypass <arg>                     目标密钥口令
 -noprompt                              不提示
 -providerclass <providerclass>         提供方类名
 -providerarg <arg>                     提供方参数
 -providerpath <pathlist>               提供方类路径
 -v                                     详细输出
keytool -keypasswd -help(更改条目的秘钥口令)

 -alias <alias>                  要处理的条目的别名
 -keypass <arg>                  密钥口令
 -new <arg>                      新口令
 -keystore <keystore>            密钥库名称
 -storepass <arg>                密钥库口令
 -storetype <storetype>          密钥库类型
 -providername <providername>    提供方名称
 -providerclass <providerclass>  提供方类名
 -providerarg <arg>              提供方参数
 -providerpath <pathlist>        提供方类路径
 -v                              详细输出
keytool -list -help(列出秘钥库中的条目)

 -rfc                            以 RFC 样式输出
 -alias <alias>                  要处理的条目的别名
 -keystore <keystore>            密钥库名称
 -storepass <arg>                密钥库口令
 -storetype <storetype>          密钥库类型
 -providername <providername>    提供方名称
 -providerclass <providerclass>  提供方类名
 -providerarg <arg>              提供方参数
 -providerpath <pathlist>        提供方类路径
 -v                              详细输出
 -protected                      通过受保护的机制的口令
keytool -printcert -help(打印证书的内容)

 -rfc                        以 RFC 样式输出
 -file <filename>            输入文件名
 -sslserver <server[:port]>  SSL 服务器主机和端口
 -jarfile <filename>         已签名的 jar 文件
 -v                          详细输出
keytool -printcertreq -help(打印证书请求的内容)

-file <filename>  输入文件名
 -v                详细输出
keytool -printcrl -help(打印CRL文件的内容)

 -file <filename>  输入文件名
 -v                详细输出
keytool -storepasswd -help(更改秘钥库的储存口令)

 -new <arg>                       新口令
 -keystore <keystore>             密钥库名称
 -storepass <arg>                 密钥库口令
 -storetype <storetype>           密钥库类型
 -providername <providername>     提供方名称
 -providerclass <providerclass>   提供方类名
 -providerarg <arg>               提供方参数
 -providerpath <pathlist>         提供方类路径
 -v                               详细输出

Guess you like

Origin blog.csdn.net/weixin_46005137/article/details/107391872