Search code examples
javakeytoolself-signed

Extract private key from self signed .jks file in java


I have signed .jks file. Need to get private key from the .jks file. How can get?

keytool -exportcert -alias selfrest -keystore filename.jks -file file.cer

Did not get the result. please help me. Thanks in advance.


Solution

  • You cannot directly export private key using Java's keytool. You have to use other tools like openssl to do it.

    First you have to convert your jks to pkcs12 format, and then use openssl to export the private key, like shown here and here.