How to connect to a secure website using SSL in Java with a pkcs12 file?

前端 未结 8 1349
野性不改
野性不改 2020-12-01 06:37

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 t

8条回答
  •  抹茶落季
    2020-12-01 07:11

    I cannot comment because of the 50pts threshhold, but I don't think that the answer provided in https://stackoverflow.com/a/537344/1341220 is correct. What you are actually describing is how you insert server certificates into the systems default truststore:

    $JAVA_HOME/jre/lib/security/cacerts, password: changeit)
    

    This works, indeed, but it means that you did not really specify a trust store local to your project, but rather accepted the certificate universially in your system.

    You actually never use your own truststore that you defined here:

    System.setProperty("javax.net.ssl.trustStore", "myTrustStore");
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
    

提交回复
热议问题