Convert cert to PFX

From Wiki
Jump to: navigation, search
#!/bin/bash
[ -n "$1" -a "$2" ]  || { echo "Usage: ./crt2pfx cert.crt .keyfile cert_name"; exit 0 ; }

openssl x509 -in $1 -out input.der -outform DER;

openssl x509 -in input.der -inform DER -out output.pem -outform PEM;

openssl pkcs12 -export -in output.pem -inkey $2 -out $3.pfx -name "$3";

echo "cleaning up...";
sleep 1;

echo "Removing input.der";
rm input.der;
sleep 1;

echo "Removing output.pem";
rm output.pem;
sleep 1;

exit 0;