--------------- 使用jdk生成证书(证书里面有公钥私钥) ----------------- 1.生成密钥证书 下边命令生成密钥证书,采用RSA 算法每个证书包含公钥和私钥 keytool -genkeypair -alias beijingliupei -keyalg RSA -keypass beijingliupei -keystore beijingliupei.jks -storepass beijingliupei 2.Keytool 是一个java提供的证书管理工具 -alias:密钥的别名 -keyalg:使用的hash算法 -keypass:密钥的访问密码 -keystore:密钥库文件名,beijingliupei.jks保存了生成的证书 -storepass:密钥库的访问密码 3.cmd输入上面的命令即可(生成的地址就在C:\Users\Administrator) C:\Users\Administrator>keytool -genkeypair -alias beijingliupei -keyalg RSA -keypass beijingliupei -keystore beijingliupei.jks -storepass beijingliupei 您的名字与姓氏是什么? [Unknown]: beijingliupei 您的组织单位名称是什么? [Unknown]: beijingliupei 您的组织名称是什么? [Unknown]: beijingliupei 您所在的城市或区域名称是什么? [Unknown]: beijingliupei 您所在的省/市/自治区名称是什么? [Unknown]: beijingliupei 该单位的双字母国家/地区代码是什么? [Unknown]: CN CN=beijingliupei, OU=beijingliupei, O=beijingliupei, L=beijingliupei, ST=beijingliupei, C=zh是否正确? [否]: y --------------- 导出公钥私钥(jdk生成证书)私钥加盐 ----------------- 1.安装 openssl是一个加解密工具包,这里使用openssl来导出公钥信息。 安装 openssl:http://slproweb.com/products/Win32OpenSSL.html 安装资料目录下的Win64OpenSSL-1_1_1b.exe 2.安装步骤(看下文) 安装成功查看版本 D:\asp> openssl version -a OpenSSL 1.1.1b 26 Feb 2019 built on: Wed Feb 27 02:30:51 2019 UTC platform: VC-WIN64A options: bn(64,64) rc4(16x,int) des(long) idea(int) blowfish(ptr) compiler: cl /Z7 /Fdossl_static.pdb /Gs0 /GF /Gy /MD /W3 /wd4090 /nologo /O2 -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPADLOCK_ASM -DPOLY1305_ASM -D_USING_V110_SDK71_ -D_WINSOCK_DEPRECATED_NO_WARNINGS OPENSSLDIR: "C:\Program Files\Common Files\SSL" ENGINESDIR: "C:\Program Files\OpenSSL\lib\engines-1_1" Seeding source: os-specific 3.生成 cmd进入 beijingliupei.jks文件所在目录执行如下命令: keytool -list -rfc --keystore beijingliupei.jks | openssl x509 -inform pem -pubkey 4.生成示例 D:\asp>keytool -list -rfc --keystore beijingliupei.jks | openssl x509 -inform pem -pubkey 输入密钥库口令: beijingliupei -----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgVpPsuWJpt1qR5qPSlJ0 DEn2HixHVua7Vn1HueZIUCQXohAqdcdZLFWY7mgCxs3ms2UYOfLM5QRiGgzd260Q g91INZ/qR8joP+QKOl5eqydE8Lh7Rg4phog3GMAhwCDySQ6WM11dkHWYiUINlBy/ 6EW4GxZD1gI9XQR9SKhO7sAy1Hms8HIcuiGIPUylxkJj6+DdYPnPsftUolTfHBL0 QdBcjcr1SFT8lSgMKBwe2huhvv4Km5ZinkWXDgUWQJ04S/tzpmktforDoN9+LnxB rGmU9HIEpzDDb+3Ar6Jyml2YTZ0hkeDzpqEWPjIYuNoOBb8ZK2yR7I76aGNlt54N BwIDAQAB -----END PUBLIC KEY----- -----BEGIN CERTIFICATE----- MIIDkTCCAnmgAwIBAgIEWLbY2zANBgkqhkiG9w0BAQsFADB5MQswCQYDVQQGEwJD TjEQMA4GA1UECBMHYmVpamluZzEQMA4GA1UEBxMHYmVpamluZzEWMBQGA1UEChMN YmVpamluZ2xpdXBlaTEWMBQGA1UECxMNYmVpamluZ2xpdXBlaTEWMBQGA1UEAxMN YmVpamluZ2xpdXBlaTAeFw0yMDA4MT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