Java: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

前端 未结 23 1519
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 04:44

I have a class that will download a file from a https server. When I run it, it returns a lot of errors. It seems that I have a problem with my certificate

23条回答
  •  无人共我
    2020-11-22 05:03

    Simple Steps that I followed.

    problem: I was trying to connect to an endpoint(https://%s.blob.core.windows.net) using a simple java class(main method).

    So I was getting this certification issue as mentioned above, in the question.

    Solution:

    1. Get the certificate using a browser(chrome). To do this paste your endpoint URL in the browser and enter. Now you will see a lock icon, click on that -->certificate--> details --> copy to files--> download it.

    2. open the cmd(i am using windows) as admin and then navigate to the directory where you have downloaded the .cer file.

    3.(Optional)If you are using multiple JDK in the same machine then change your JDK version the same as you are using in your application.

    1. Now use the below command

    keytool -import -alias mycertificate -keystore "C:\Program Files\Java\jdk-11.0.5\lib\security\cacerts" -file myurlcrt.cer

    1. Give the default password: changeit

    2. Trust this certificate: yes

    And you are done.

    Thanks!

提交回复
热议问题