当前位置:网站首页>使用KeyStore生成证书
使用KeyStore生成证书
2022-08-01 09:50:00 【十玖八柒】
前言
Keytool是一个Java数据证书的管理工具 , 在keystore里,包含两种数据:
- 密钥实体(Key entity):即密钥(secret key)又或者是私钥和配对公钥(采用非对称加密)
- 可信任的证书实体(trusted certificate entries):即证书(包含公钥)
keytool常用命令:
- genkey 在用户主目录中创建一个默认文件”.keystore”
- alias 产生别名
- keystore 指定密钥库的名称(产生的各类信息将不在.keystore文件中)
- keyalg 指定密钥的算法 (如 RSA DSA(如果不指定默认采用DSA))
- validity 指定创建的证书有效期多少天
- keysize 指定密钥长度
- storepass 指定密钥库的密码(获取keystore信息所需的密码)
- keypass 指定别名条目的密码(私钥的密码)
- dname 指定证书拥有者信息 例如: “CN=名字与姓氏,OU=组织单位名称,O=组织名称,L=城市或区域名称,ST=州或省份名称,C=单位的两字母国家代码”
- list 显示密钥库中的证书信息 keytool -list -v -keystore 指定keystore -storepass 密码
- v 显示密钥库中的证书详细信息
- export 将别名指定的证书导出到文件 keytool -export -alias 需要导出的别名 -keystore 指定keystore -file 指定导出的证书位置及证书名称 -storepass 密码
- file 参数指定导出到文件的文件名
- delete 删除密钥库中某条目 keytool -delete -alias 指定需删除的别 -keystore 指定keystore -storepass 密码
- printcert 查看导出的证书信息 keytool -printcert -file abc.crt
- keypasswd 修改密钥库中指定条目口令 keytool -keypasswd -alias 需修改的别名 -keypass 旧密码 -new 新密码 -storepass keystore密码 -keystore sage
- storepasswd 修改keystore口令 keytool -storepasswd -keystore e:\abc.keystore(需修改口令的keystore) -storepass 123456(原始密码) -new abc(新密码)
- import 将已签名数字证书导入密钥库 keytool -import -alias 指定导入条目的别名 -keystore 指定keystore -file 需导入的证书
创建一个Keystore证书
keytool -genkeypair -alias serverkey -keyalg RSA -keysize 2048 -validity 3650 -keystore CATest.keystore说明: storepass keystore 文件存储密码,不加这个参数会在后面要求你输入密码 keypass 私钥加解密密码 alias 实体别名(包括证书私钥) dname 证书个人信息 keyalg 采用公钥算法,默认是DSA,这里采用RSA keysize 密钥长度(DSA算法对应的默认算法是sha1withDSA,不支持2048长度,此时需指定RSA) validity 有效期 keystore 指定keystore文件储存位置
设置密钥口令,及证书信息,输入Y确定,生成证书
查看证书信息:
keytool -v -list -keystore CATest.keystore导出为cer公钥证书:
keytool -exportcert -keystore CATest.keystore -file CATest.cer -alias serverkey如果要导出crt的话,只需要改后缀即可(下面的证书也是同理):
keytool -exportcert -keystore CATest.keystore -file CATest.crt -alias serverkey创建一个JKS证书
与keystore证书同理 生成JKS证书:
keytool -genkey -alias testClient -keyalg RSA -keysize 1024 -keystore CATest.jks -validity 365查看证书信息:
keytool -list -v -keystore CATest.jks导出为cer文件证书:
keytool -alias testClient -exportcert -keystore CATest.jks -file CATest.cer创建P12证书
keytool -genkey -v -alias testClient -keyalg RSA -storetype PKCS12 -keystore CATest.p12查看证书信息:
keytool -list -v -keystore CATest.p12导出为cer文件证书:
keytool -export -alias testClient -keystore CATest.p12 -storetype PKCS12 -storepass 密钥口令 -rfc -file CATest.cer格式转化
将公钥证书导出密钥库: 将cer公钥证书转为keystore证书
keytool -import -v -file CATest.cer -keystore CATest2.keystore将keystore转为p12:
keytool -importkeystore -srckeystore CATest.keystore -destkeystore CATest2.p12 -srcalias serverkey -destalias serverkey -srcstoretype jks -deststoretype pkcs12 -noprompt边栏推荐
- InputStream转成String
- [Software Architecture Mode] The difference between MVVM mode and MVC mode
- Change Servlet project to SSM project
- 会议OA(待开会议&所有会议)
- 【无标题】
- PerViT: 神经网络也能像人类利用外围视觉一样观察图像!
- Install GBase 8 c database, the error shows "Resource, how to solve?
- Optimal dazzle Oracle database support what kinds of type of the time and date
- IntellJ IDEA如何显示换行符(line endings)
- 可视化——Superset安装与部署
猜你喜欢
随机推荐
Introduction and application of heap memory (including examples)
Quantify daily work metrics
已解决(pip安装库报错)Consider using the-- user option or check the permissions.
Change Servlet project to SSM project
Yang Hui Triangle (C language implementation)
解决new Thread().Start导致高并发CPU 100%的问题
PHP获取时间戳后写数据库的一个问题
notes....
DBPack SQL Tracing 功能及数据加密功能详解
VS“无法查找或打开PDB文件”是怎么回事?如何解决
Taobao commodity details and details on taobao, senior upgrade version of the API
安装GBase 8c数据库的时候,报错显示“Resource,如何解决?
Introduction to ADAS
redis
WLAN networking experiment of AC and thin AP
UXDB如何返回当前数据库所有表的记录数?
18张图,直观理解神经网络、流形和拓扑
【面试:并发篇39:多线程:线程池】ThreadPoolExecutor类-提交、停止
[Interview: Concurrency 39: Multithreading: Thread Pool] ThreadPoolExecutor Class - Submit, Stop
《时代》杂志:元宇宙时代将改变世界









