Skip to content

Instantly share code, notes, and snippets.

@valtoni
Created May 29, 2016 13:36
Show Gist options
  • Save valtoni/52fbd82a95fc9f47787a7a83b337dd90 to your computer and use it in GitHub Desktop.
Save valtoni/52fbd82a95fc9f47787a7a83b337dd90 to your computer and use it in GitHub Desktop.
Script to export certificate and private key from jks store
#!/bin/bash
FILE=$1
OUTPUT_NAME=$2
# Export to PKCS12 format
keytool -importkeystore -srckeystore "$FILE" -destkeystore "$OUTPUT_NAME".p12 -deststoretype PKCS12
# Export certificate in pem format
openssl pkcs12 -in "$OUTPUT_NAME".p12 -nokeys -out "$OUTPUT_NAME"_cert.pem
# Export certificate in x509 format
openssl x509 -outform der -in "$OUTPUT_NAME"_cert.pem -out "$OUTPUT_NAME"_cert.crt
# Export unencripted key in pem format
openssl pkcs12 -in "$OUTPUT_NAME".p12 -nodes -nocerts -out "$OUTPUT_NAME"_key.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment