zoukankan      html  css  js  c++  java
  • KeyTool 使用简介

    keytool 是个密钥和证书管理工具。它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数字签名)自我认证(用户向别的用户/服务认证自己)或数据完整性以及认证服务。它还允许用户储存他们的通信对等者的公钥(以证书形式)。

    keytool 将密钥和证书储存在一个所谓的密钥仓库中。缺省的密钥仓库实现将密钥仓库实现为一个文件。它用口令来保护私钥。

    1.使用 -genkey

    改参数是用来生成秘钥对。格式如下:keytool -genkey -alias duke -keypass mypassword

    2. -genkeypair

    创建证书库(keystore)及证书(Certificate) 

    Keytool -genkeypair -alias test.mydomain.com -keyalg RSA -keysize 2048 -keypass mypassword -sigalg SHA256withRSA -dname "CN=test.mydomain.com,OU=test,O=test,L=beijing,C=CN" -validity 5475 -keystore D:\test.mydomain.com -keystore.p12 -storetype PKCS12-storepass mypassword

    3. -certreq

    生成证书请求(CSR),使用格式如下:

    keytool -certreq -keyalg RSA -alias test.mydomain.com -keystore D:\test.mydomain.com_keystore.p12 -storetype PKCS12 -storepass mypassword -file D:\test.mydomain.com_certreq.csr

    这样我们就可以吧生成的请求证书发给证书颁发机构去创建证书了。在完成证书申请后,会给我们三个文件:一级根证书,二级根证书和三级证书。我们还是要用keytool将颁发的证书合并到上面生成的P12文件中

    keytool -import -trustcacerts -keystore D:\test.mydomain.com_keystore.p12 -storepass mypassword -alias root-file D:\root.cer(导入一级证书)

    keytool -import -trustcacerts -keystore D:\test.mydomain.com_keystore.p12 -storepass mypassword -alias issuer-file D:\issuer.cer(导入二级证书)

    keytool -import -trustcacerts -keystore D:\test.mydomain.com_keystore.p12 -storepass mypassword -companyroot-file D:\company.cer(导入三级证书)

    4.遇到的问题

    如果按照上面使用keytool -import将证书文件导入到P12文件中,你会遇到invalid keystore format,明明是正确的P12文件,为啥会报这样的错误呢。

    我们在使用Keytoo -genkeypair的时候收使用参数-storetype指定为PCKS12的类型,我们在使用keytool -import的时候也要使用该数据就可以了,重新输入如下到CMD中就一切正常了。

    keytool -import -trustcacerts -keystore D:\test.mydomain.com_keystore.p12 -storepass mypassword -storetype PKCS12 -alias root-file D:\root.cer(导入一级证书)

    keytool -import -trustcacerts -keystore D:\test.mydomain.com_keystore.p12 -storepass mypassword  -storetype PKCS12 -alias issuer-file D:\issuer.cer(导入二级证书)

    keytool -import -trustcacerts -keystore D:\test.mydomain.com_keystore.p12 -storepass mypassword  -storetype PKCS12 -companyroot-file D:\company.cer(导入三级证书)

  • 相关阅读:
    客户端本地存储,web存储,localStorage
    js地理定位对象 navigator.geolocation
    使用defined和require引入js
    VUE的使用方法
    $.each()的用法
    jQuery的deferred对象详解
    jquery 中prop()的使用方法
    IE7下对某些seajs压缩文件不兼容的解决方法
    饼状图注释
    $.grep()的用法
  • 原文地址:https://www.cnblogs.com/VARForrest/p/15719003.html
Copyright © 2011-2022 走看看