我使用此命令创建了 CSR 请求:
openssl req -out certificatecsr.csr -new -newkey rsa:2048 -keyout certificatekey.key
之后 CA 与我共享证书(.cer)文件。
现在,我使用密钥将 .cer 文件转换为 .p12。
使用 CA 发送的 cer 和私钥创建 .p12 证书
C:\Java\jdk1.6.0_38\jre\bin>openssl pkcs12 -export -in C:\Users\aharma1\cert.cer -inkey certificatekey.key -out
证书p12
创建 JKS 密钥库:
keytool -genkey -alias quid -keystore quid.jks
将 .p12 证书导入 jks 密钥库
C:\Java\jdk1.6.0_38\jre\bin>keytool -v -importkeystore -srckeystore C:\OpenSSL-Win64\bin\certi.p12 -srcstoretype PKCS12
-destkeystore quid.jks -deststoretype JKS
但是当我从我的 java 代码中引用这个 JKS 时,我收到了这个错误:
sun.security.validator.ValidatorException:PKIX 路径构建失败:
sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径
我还将 cer 文件添加到 cacerts.但仍然遇到相同的错误。
就 JAVA 代码而言,我引用此链接来引用我自己创建的密钥库:
http://jcalcote.wordpress.com/2010/06/22/managing-a-dynamic-java-trust-store/
public SSLContext getSSLContext(String tspath)
throws Exception {
TrustManager[] trustManagers = new TrustManager[] {
new ReloadableX509TrustManager(tspath)
};
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
return sslContext;
}
SSLContext sslContext=getSSLContext("C:\\Java\\jdk1.6.0_38\\jre\\bin\\quid.jks");
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
URL pickUrl = new URL(pickupLocation);
URLConnection urlConn = pickUrl.openConnection();
HttpsURLConnection httpsURLConn = (HttpsURLConnection)urlConn;
httpsURLConn.setSSLSocketFactory(socketFactory);
String encoding = urlConn.getContentEncoding();
InputStream is = urlConn.getInputStream();
InputStreamReader streamReader = new InputStreamReader(is, encoding != null
? encoding : "UTF-8");
请注意我没有使用任何服务器。我正在尝试仅通过主要方法在编写的代码之上运行。
请让我知道需要做什么。为什么我需要将我的 .cer 文件转换为 .p12 文件?