有时候需要做一些证书,特别是安卓接入SDK,提交包什么的需要填入公钥私钥信息,可能需要RSA 1024位或其他位数的信息。
这里提供一个能获取keystore信息和公钥私钥的命令。
openssl我就不再写了,自己再百度下怎么处理。
生成keystore
keytool -genkey -alias "companyname" -keyalg “RSA” -keysize 1024 -keystore "companyname.keystore" -validity 7300 -dname "CN=CompanyName,OU=Citicbank,O=Citic,L=CHENGDU,ST=SICHUAN,C=CN"
2. 查看keystore信息
keytool -list -v -keystore E:\Keys\companyname.keystore -storepass Pwd123456
3. 导出公钥文件
keytool -export -alias "companyname" -file "E:\Keys\companyname.cer" -keystore "companyname.keystore"
4. 转换成pem证书
openssl x509 -inform der -in companyname.cer -out companyname.pem
5. 查看公钥
keytool -list -rfc --keystore companyname.keystore | openssl x509 -inform pem -pubkey
拿到公钥信息:
-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZmCuuBWqVMLNUEN44NNj7eb2w2CjbiYeDmmx7vHPUrgk2DipeP6owUxpYimjzcrS4tY0Aqv+Wuy+Gvukb943Yb1AoSqWs5mLC4JJZmIh4FgV0d3kOE0wJeDzfwR/TJOCTq+HRyLHfTGUaIvM7JwEqDyP9NbfCXG54WbOLBPxzUwIDAQAB-----END PUBLIC KEY-----
keystore导出私钥(.key)操作步骤
1. 从JKS转换到PKCS12
keytool -importkeystore -srckeystore companyname.keystore -destkeystore companyname.p12 -srcstoretype JKS -deststoretype PKCS12 -srcstorepass Pwd123456 -deststorepass Pwd123456 -srcalias companyname -destalias companyname -srckeypass Pwd123456 -destkeypass Pwd123456 -noprompt
2. 从PKCS12转换成PEM格式
openssl pkcs12 -in companyname.p12 -out companyname.pem -passin pass:Pwd123456 -passout pass:Pwd123456
3. 生成私钥companyname_private_key.pem文件
openssl pkcs12 -in companyname.p12 -nodes -nocerts -out companyname_private_key.pem
拿到私钥信息:
-----BEGIN RSA PRIVATE KEY-----MIICXAIBAAKBgQCZmCuuBWqVMLNUEN44NNj7eb2w2CjbiYeDmmx7vHPUrgk2DipeP6owUxpYimjzcrS4tY0Aqv+Wuy+Gvukb943Yb1AoSqWs5mLC4JJZmIh4FgV0d3kOE0wJeDzfwR/TJOCTq+HRyLHfTGUaIvM7JwEqDyP9NbfCXG54WbOLBPxzUwIDAQABAoGAEIZhtLBafkCmGpZSAkQVUEER2pP3GV+bl9omb82fvLMYxJsTjd5Vpitau0nw7rhZn0HRMNA0/XeYLmwd0md4+DNLppDA2BR0Enln8yYFbcHwmp6MjXDO0i2qXIBhYfHL+YaKyHdVEOSKBbCGqjGEQXkvujfhNWSln0Jym/g0jmECQQD+OF7F7HlON3gAzOWshbaPyGrNRwIRw55sHYMtIvYpsMMd7KjwpRY5a6wOWu8xpOdQy5ecUTRoAdFB4p8lSXWjAkEAmqtz0cnDd8cf1UNhn9Fi98HKs/37sOwLeEwohfo8wJch5kf5rVVtadwfPP3beRoS1rMvjXCsmmH7W9wpT9UGkQJAIpzUMoiG36JnwVwkbT/rYlo8SGTBoF+NA1VlVdDryTNa7YkaW2FuzDSfwXiaFp1ILVT6+HqJ8xtEPX84geAllwJAJDDwNeuXMGTInxdYNZRCKyUOcFWC2mAxQuHXLZpjMtFqXj8DPjraEkYujQ/9lfWy6Mge3WK7EJjSvyjiBcsb8QJBAJX2gLa8G1N/TPJgJYS6AEXDI6WeqxkGUV6tfo0Cyzi8y1aPXeFpftzrZoxneaXLh/fCfj7QMtty/qAPtjhRkTA=-----END RSA PRIVATE KEY-----
可以随便找个在线网站测试一下:
来源地址:https://blog.csdn.net/u013476751/article/details/127521039