Skip to content

Instantly share code, notes, and snippets.

@RecuencoJones
Last active August 27, 2019 12:16
Show Gist options
  • Save RecuencoJones/80bf2c22ec859727f158102fcd0f79f2 to your computer and use it in GitHub Desktop.
Save RecuencoJones/80bf2c22ec859727f158102fcd0f79f2 to your computer and use it in GitHub Desktop.
JKS -> PEM & CRT + KEY
#!/usr/bin/env bash
if [[ -z $SUBJECT ]] && [[ -z $1 ]] ; then
read -p "Subject: " SUBJECT
fi
if [[ -z $PASSPHRASE ]] && [[ -z $2 ]] ; then
read -p "Passphrase: " PASSPHRASE
fi
subject=${SUBJECT:-$1}
passphrase=${PASSPHRASE:-$2}
keytool -importkeystore \
-srckeystore $subject.jks \
-destkeystore $subject.p12 \
-srcalias $subject \
-srcstoretype jks \
-deststoretype pkcs12 \
-srcstorepass $passphrase \
-deststorepass $passphrase \
-no-prompt
openssl pkcs12 -in $subject.p12 -out $subject.pem -passin pass:$passphrase -passout pass:$passphrase
openssl pkey -in $subject.pem -out private.key -passin pass:$passphrase
openssl x509 -in $subject.pem -out public.crt -passin pass:$passphrase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment