Oracle 已经编写了关于将 PEM 转换为密钥库的完整说明。它还涵盖了 p12。这可能会做你想要的。
不幸的是,搜索引擎很难找到它,因为他们称之为“JKS”而不是密钥库。
简而言之:
使用以下命令将证书从 PEM 转换为 PKCS12:openssl pkcs12 -export -out eneCert.pkcs12 -in eneCert.pem
您可以忽略此命令发出的警告消息。输入并重复导出密码。使用以下命令创建然后删除一个空的信任库:
keytool -genkey -keyalg RSA -alias endeca -keystore truststore.ks
keytool -delete -alias endeca -keystore truststore.ks
-genkey 命令创建如下所示的默认证书。(这是一个临时证书,随后会被 -delete 命令删除,因此您在此处输入什么信息都没有关系。)
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]:
What is the name of your organizational unit?
[Unknown]:
What is the name of your organization?
[Unknown]:
What is the name of your City or Locality?
[Unknown]:
What is the name of your State or Province?
[Unknown]:
What is the two-letter country code for this unit?
[Unknown]:
Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
[no]: yes
Enter key password for <endeca>
(RETURN if same as keystore password):
Re-enter new password:
使用以下命令将 CA 导入信任库:keytool -import -v -trustcacerts -alias endeca-ca -file eneCA.pem -keystore truststore.ks
输入密钥库密码。出现提示“信任此证书?” 输入是。使用以下命令创建一个空的 Java KeyStore:
keytool -genkey -keyalg RSA -alias endeca -keystore keystore.ks
keytool -delete -alias endeca -keystore keystore.ks
-genkey 命令创建如下所示的默认证书。(这是一个临时证书,随后会被 -delete 命令删除,因此您在此处输入什么信息都没有关系。)
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]:
What is the name of your organizational unit?
[Unknown]:
What is the name of your organization?
[Unknown]:
What is the name of your City or Locality?
[Unknown]:
What is the name of your State or Province?
[Unknown]:
What is the two-letter country code for this unit?
[Unknown]:
Is CN="Unknown", OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
[no]: yes
使用以下命令将您的私钥导入空 JKS:
keytool -v -importkeystore -srckeystore eneCert.pkcs12 -srcstoretype PKCS12 -destkeystore keystore.ks -deststoretype JKS