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

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

I have this in an ActiveMQ config:


        

        
15条回答
  •  抹茶落季
    2020-11-22 08:31

    Previous answers point out correctly that you can only do this with the standard JDK tools by converting the JKS file into PKCS #12 format first. If you're interested, I put together a compact utility to import OpenSSL-derived keys into a JKS-formatted keystore without having to convert the keystore to PKCS #12 first: http://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art049

    You would use the linked utility like this:

    $ openssl req -x509 -newkey rsa:2048 -keyout localhost.key -out localhost.csr -subj "/CN=localhost"
    

    (sign the CSR, get back localhost.cer)

    $ openssl rsa -in localhost.key -out localhost.rsa
    Enter pass phrase for localhost.key:
    writing RSA key
    $ java -classpath . KeyImport -keyFile localhost.rsa -alias localhost -certificateFile localhost.cer -keystore localhost.jks -keystorePassword changeit -keystoreType JKS -keyPassword changeit
    

提交回复
热议问题