Skip to content

Instantly share code, notes, and snippets.

@althafvly
Last active February 6, 2023 10:14
Show Gist options
  • Save althafvly/5014ee4603532192eb1b662aedd876ee to your computer and use it in GitHub Desktop.
Save althafvly/5014ee4603532192eb1b662aedd876ee to your computer and use it in GitHub Desktop.
eg: bash jksgenerator.sh platform
#!/bin/bash
if [ "$#" -eq "0" ]; then
echo "No arguments supplied"
exit 1
elif [ $# -eq 1 ]; then
if test -f "$1.pk8"; then
checkPass=$(grep "ENCRYPTED" "$1.pem" &>/dev/null)
if [ $? -eq 0 ]; then
openssl pkcs8 -in $1.pk8 -inform DER -outform PEM -out $1.priv.pem
else
openssl pkcs8 -in $1.pk8 -nocrypt -inform DER -outform PEM -out $1.priv.pem
fi
echo "Done $1.priv.pem"
else
echo "$1.pk8 not found"
exit 1
fi
if test -f "$1.x509.pem"; then
openssl pkcs12 -export -in $1.x509.pem -inkey $1.priv.pem -out $1.pk12 -name $1
echo "Done $1.pk12"
else
echo "$1.x509.pem not found"
exit 1
fi
keytool -importkeystore -destkeystore $1.jks -srckeystore $1.pk12 -srcstoretype PKCS12 -alias $1
echo "alias: $1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment