Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fabiocannas/13d35b62d5a0897e35fa6f6c050a8faf to your computer and use it in GitHub Desktop.
Save fabiocannas/13d35b62d5a0897e35fa6f6c050a8faf to your computer and use it in GitHub Desktop.
Android Mobile App development - Export Private Key from .jks file
Export the Private Key: First, you need to convert the JKS keystore to a PKCS12 format:
  keytool -importkeystore -srckeystore [keystore_path] -destkeystore [output_file.p12] -deststoretype PKCS12 -srcstorepass [password] -deststorepass [password]
Replace [keystore_path] with the path to your JKS file, [output_file.p12] with the desired output file name, and [password] with the keystore password.
Extract the Private Key: Use OpenSSL to extract the private key from the PKCS12 file:
  openssl pkcs12 -in [output_file.p12] -nocerts -out [private_key.pem] -nodes
Replace [output_file.p12] with the name of the PKCS12 file and [private_key.pem] with the desired output file name for the private key.
Convert to PEM Format: If needed, convert the private key to the required PEM format:
  openssl pkcs8 -topk8 -inform PEM -outform PEM -in [private_key.pem] -out [formatted_private_key.pem] -nocrypt
Replace [private_key.pem] with the path to your extracted private key and [formatted_private_key.pem] with the desired output file name.
This process should give you the private key in the format:
-----BEGIN PRIVATE KEY-----
YourPrivateKeyHere
-----END PRIVATE KEY-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment