How to import a .cer certificate into a java keystore?

后端 未结 8 852
有刺的猬
有刺的猬 2020-11-22 15:38

During the development of a Java webservice client I ran into a problem. Authentication for the webservice is using a client certificate, a username and a password. The clie

相关标签:
8条回答
  • 2020-11-22 16:33

    Here's how this worked for me:

    1. Save as .txt the certificate data in the following format in a text editor

      -----BEGIN CERTIFICATE----- [data serialized by microsoft] -----END CERTIFICATE-----

    2. Open chrome browser (this step might work with other browsers too) settings > show advanced settings > HTTPS/SSL > manage certificates Import the .txt in step 1
    3. Select and export that certificate in Base-64 encoded format. Save it as .cer
    4. Now you can use keytool or Portecle to import it to your java keystore
    0 讨论(0)
  • 2020-11-22 16:35

    You shouldn't have to make any changes to the certificate. Are you sure you are running the right import command?

    The following works for me:

    keytool -import -alias joe -file mycert.cer -keystore mycerts -storepass changeit
    

    where mycert.cer contains:

    -----BEGIN CERTIFICATE-----
    MIIFUTCCBDmgAwIBAgIHK4FgDiVqczANBgkqhkiG9w0BAQUFADCByjELMAkGA1UE
    BhMCVVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAY
    ...
    RLJKd+SjxhLMD2pznKxC/Ztkkcoxaw9u0zVPOPrUtsE/X68Vmv6AEHJ+lWnUaWlf
    zLpfMEvelFPYH4NT9mV5wuQ1Pgurf/ydBhPizc0uOCvd6UddJS5rPfVWnuFkgQOk
    WmD+yvuojwsL38LPbtrC8SZgPKT3grnLwKu18nm3UN2isuciKPF2spNEFnmCUWDc
    MMicbud3twMSO6Zbm3lx6CToNFzP
    -----END CERTIFICATE-----
    
    0 讨论(0)
提交回复
热议问题