安全证书使用指南

一、安全证书的种类

1、JKS(JAVA KEY STORE)是java的keytools证书工具支持的证书私钥格式

2、pfx 是微软支持的私钥格式,由Public Key Cryptography Standards #12,PKCS#12标准定义,包含了公钥和私钥的二进制格式的证书形式,以pfx作为证书文件后缀名(文件的扩展名可以为pfx或p12)

3、cer 是证书的公钥

4、什么是CA ?
CA就相当于一个认证机构,只要经过这个机构签名的证书我们就可以当做是可信任的。我们的浏览器中,已经被写入了默认的CA根证书。

二、keytool的用法

C:\Users>keytool -v
密钥和证书管理工具

命令:

 -certreq            生成证书请求
 -changealias        更改条目的别名
 -delete             删除条目
 -exportcert         导出证书
 -genkeypair         生成密钥对
 -genseckey          生成密钥
 -gencert            根据证书请求生成证书
 -importcert         导入证书或证书链
 -importpass         导入口令
 -importkeystore     从其他密钥库导入一个或所有条目
 -keypasswd          更改条目的密钥口令
 -list               列出密钥库中的条目
 -printcert          打印证书内容
 -printcertreq       打印证书请求的内容
 -printcrl           打印 CRL 文件的内容
 -storepasswd        更改密钥库的存储口令

更多命令描述请查看官网:keytool-Key and Certificate Management Tool

三、不同证书如何生成

1.JKS证书生成

1.创建CA证书,用于生成客户端服务端证书.

keytool -genkey -alias root -keyalg RSA -keystore root.jks

2.生成客户端证书

keytool -export -alias -file client.cer -keystore root.jks

3.生成服务端证书.

keytool -export -alias -file server.cer -keystore root.jks

2.PFX证书生成

        通过IE浏览器导出pfx证书

四、不同证书之间的转化

1.pfx证书转化成JKS

keytool.exe  -importkeystore -srckeystore  testDemo.pfx -srcstoretype pkcs12 -destkeystore testDemo.jks -deststoretype JKS

keytool.exe -v -importkeystore -srckeystore clinet.jks -srcstoretype jks -srcstorepass testDemo -destkeystore client.pfx -deststoretype pkcs12 -deststorepass testDemo -destkeypass testDemo

2. 查看证书信息

keytool -list -v -keystore testDemo.jks

3.导出公钥信息

1.导出cer

keytool -exportcert -rfc -alias {12332db3-40f8-4703-a5d5-6610d4a111a9} -file testDemo.cer -keystore testDemo.jks -storepass ****

2.导出cert

keytool -export -alias {12332db3-40f8-4703-a5d5-6610d4a111a9} -keystore testDemo.jks -rfc -file publickey.cert

4.更改别名

keytool -changealias -keystore dev.jks -alias old_alias -destalias new

5.一个jks合并到另一个里面

keytool -importkeystore -srckeystore prod.jks -destkeystore common.jks -srcalias myRootCA -destalias myRootCA_PROD -srcstorepass **** -deststorepass ****

6.查看pfx证书内容

openssl pkcs12 -info -in server.pfx
openssl x509 -in CFCA_EV_ROOT.cer-noout -text |less

openssl.exe pkcs12 -info -in client.pfx | openssl.exe x509 -noout -text

7.jks导入cer公钥

keytool.exe -importcert -keystore client.jks -alias "1" -file testDemo.cer

8.jks删除

 keytool.exe -delete -noprompt -alias "1" -keystore client.jks

9.秘钥解密

openssl ras -in rsa_private.key -pubout -out rsa_public.key

10.私钥转非加密

openssl.exe rsa -in key.txt -passin pass:mipay_utility  -out rsa_private.key

11.使用私钥证书和公钥合成pfx证书

 openssl.exe  pkcs12 -export -out new.pfx -inkey key_d.txt -in testDemo.cer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值