Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to connect to a secure website using SSL in Java with a pkcs12 file?
    text
    copied!<p>I have a pkcs12 file. I need to use this to connect to a webpage using https protocol. I came across some code where in order to connect to a secure web page i need to set the following system properties:</p> <pre><code>System.setProperty("javax.net.ssl.trustStore", "myTrustStore"); System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); System.setProperty("javax.net.ssl.keyStoreType", "pkcs12"); System.setProperty("javax.net.ssl.keyStore", "new_cert.p12"); System.setProperty("javax.net.ssl.keyStorePassword", "newpass"); </code></pre> <p>I have the p12(pkcs12) file. All I need is a truststore file.</p> <p>I extracted the certificates using:</p> <pre><code>openssl.exe pkcs12 -in c:/mykey.p12 -out c:/cert.txt -nokeys -clcerts </code></pre> <p>Now converted the cert PEM file to der</p> <pre><code>openssl.exe x509 -in c:/cert.txt -outform DER -out c:/CAcert.der </code></pre> <p>Now adding the der file to a keystore</p> <pre><code>keytool -import -file C:/Cacert.der -keystore mytruststore </code></pre> <p>Now I have the truststore, but when I use it, I get the following error</p> <pre><code>Exception in thread "main" java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl) </code></pre> <p>Update: After removing certain properties and setting only the "trustStore", "trustStorePassword" and "trustStoreType" property, I got the following exception</p> <pre><code>java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty </code></pre> <p>Please Help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload