Java program avoids SSL certificate problem accessing HTTPS Web site

Source: Internet
Author: User
Tags md5 ssl certificate

Part of the original, reference: reference: http://tanyongbing.iteye.com/blog/1855132


In project development, you sometimes encounter with SSL security certificate import, how to import the certificate into the Java Cacerts Certificate Library.
In fact it is very simple, the method is as follows:


Each step: Use the Firefox browser, into a https://www.xxx.com start of the Web site, the certificate to be imported to download over,
Click on the lock on the left side of the browser navigation bar to see more information about the secure link, click View Certificate, click Details, click Export,
Save Type "X.509 certificate (PEM) (*.CRT; *.pem)
For example: Save As Abc.cer, put it under C disk




Step two: How to import the above step (abc.cer) This certificate into the Java Cacerts Certificate library?
Methods are as follows
Suppose your JDK is installed in the C:\jdk1.5 directory,
Start >> run >> enter cmd into DOS command line >> (some Windows systems need to run as administrator,
And then use the CD to enter the C:\jdk1.5\jre\lib\security directory.
Typing the following command carriage return execution
Keytool-import-alias Cacerts-keystore Cacerts-file D:\software\AKAZAM-Mail.cer
At this point the command line prompts you to enter the password for the Cacerts certificate library.
You can just typing Changeit, this is the default password for the Cacerts certificate Library in Java.
You can modify it yourself.

The import is viewed with-list (no alias is specified using-alias, so it is MyKey), where MD5 corresponds to the MD5 of the certificate.
MyKey, 2012-10-26, Trustedcertentry,
Certified fingerprint (MD5): 8d:a2:89:9a:e4:17:07:0b:bd:b0:0c:36:11:39:d0:3d

Custom file and password path, has not yet been validated:
Define the Truststore using the java_opts variable on the Stash Server:
You'll have to do the following:
On Windows:
java_opts =-djavax.net.ssl.truststore= "%java_home%\jre\lib\security\cacerts"-djavax.net.ssl.truststorepassword= "Changeit"
On Linux:
java_opts =-djavax.net.ssl.truststore= "$JAVA _home/jre/lib/security/cacerts"-djavax.net.ssl.truststorepassword= " Changeit "
(info) On the I local instance truststore password are Changeit so I belive, if you didn´t changed it, your is changeit as.


The tomcat, JUnit runtime loads the Cacerts file from the default path, and if the main function runs directly, you need to specify the Javax.net.ssl.trustStore file path, such as:
java-djavax.net.ssl.truststore= $JAVA _home/jre/lib/security/cacerts-jar Xxx.jar &


Note that if there is a space in the Java_home setting, Java executes the error, you can java_home the environment variable in the C:\Program files abbreviated to C:\progra~1


Reference: http://tanyongbing.iteye.com/blog/1855132

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.