How to import an existing X.509 certificate and private key in Java keystore to use in SSL?

前端 未结 15 863
说谎
说谎 2020-11-22 08:05

I have this in an ActiveMQ config:


        

        
15条回答
  •  一向
    一向 (楼主)
    2020-11-22 08:19

    You can use these steps to import the key to an existing keystore. The instructions are combined from answers in this thread and other sites. These instructions worked for me (the java keystore):

    1. Run

    openssl pkcs12 -export -in yourserver.crt -inkey yourkey.key -out server.p12 -name somename -certfile yourca.crt -caname root

    (If required put the -chain option. Putting that failed for me). This will ask for the password - you must give the correct password else you will get an error (heading error or padding error etc).

    1. It will ask you to enter a new password - you must enter a password here - enter anything but remember it. (Let us assume you enter Aragorn).
    2. This will create the server.p12 file in the pkcs format.
    3. Now to import it into the *.jks file run:
      keytool -importkeystore -srckeystore server.p12 -srcstoretype PKCS12 -destkeystore yourexistingjavakeystore.jks -deststoretype JKS -deststorepass existingjavastorepassword -destkeypass existingjavastorepassword
      (Very important - do not leave out the deststorepass and the destkeypass parameters.)
    4. It will ask you for the src key store password. Enter Aragorn and hit enter. The certificate and key is now imported into your existing java keystore.

提交回复
热议问题