1、生成keystore文件

命令行窗口执行如下命令:

keytool -genkey -alias ynhr -keyalg RSA -keysize 1024 -keypass 123456 -validity 36500 -keystore test.keystore -storepass 123456

命令解读:

-alias 别名:ynhr

-keyalg 算法:RSA

-keysize 密码长度:1024

-keypass 私钥访问密码:123456

-validity 有效期:36500天

-keystore 名称:test.keystore

-storepass keystone文件访问密码:123456

在目录下已生成名为:test.keystore 的文件

2、keytool 通过keystone 导出p12文件

keytool -importkeystore -srcstoretype JKS -srckeystore test.keystore -srcstorepass 123456 -srcalias ynhr -srckeypass 123456 -deststoretype PKCS12 -destkeystore test.p12 -deststorepass 123456 -destalias client -destkeypass 123456 -noprompt

继续执行如上命令导出p12私钥文件

3、从p12导出格式为.key的私钥文件

openssl pkcs12 -in test.p12 -nocerts -nodes -out test.key

4、从keystore导出cer公钥证书文件

keytool -export -alias ynhr -keystore test.keystore -rfc -file test.cer

有时候需要.crt格式的文件,调整下格式即可

keytool -export -alias ynhr -keystore test.keystore -rfc -file test.crt

5、导出格式为“pem”的公钥证书文件

5.1、keytool生成keystore的转为PKCS12格式

keytool -importkeystore -srcstoretype JKS -srckeystore test.keystore -srcstorepass 123456 -srcalias ynhr -srckeypass 123456 -deststoretype PKCS12 -destkeystore test.p12 -deststorepass 123456 -destalias test -destkeypass 123456 -noprompt

5.2、opensl 从PKCS12中导出私钥

openssl pkcs12 -in test.p12 -passin pass:123456 -nocerts -out test.private

MAC verified OK

Enter PEM pass phrase:123456

Verifying - Enter PEM pass phrase:123456

5.3、opensl 从私钥导出不带签名的公钥

openssl rsa -in test.private -pubout

Enter pass phrase for client.private:123456

writing RSA key

-----BEGIN PUBLIC KEY-----

MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQClREmV3+XLyq23AKA00kYZ0exc

4CcLqhVVgavJckgwLKPKc0F0Rg8J4fKb8JBfIl9qaHa/RWh6MI50y1GKBEub5PWj

JOAwsDhhLKTOD8DU7GXJnDOcwMfFPhfcMvID98l3uK3G9fjviMcKbN3tMlW0vg0D

19msDnNhOpRKqZnULwIDAQAB

-----END PUBLIC KEY-----

6、将公钥证书导入密钥库

keytool -import -v -file bst.cer -keystore miepay.keystore

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐