Convert Certificates
The snippet can be accessed without any authentication.
Authored by
Lars Scheibling
Convert certificates from PFX to PEM (Linux)
Usage:
$ chmod +x convertcert.sh
$ ./convertcert.sh MyPFXCertificate.pfx
$ ls -al
-rwxrwxrwx 1 root root 0 Mar 21 11:47 MyPFXCertificate.key.pem
-rwxrwxrwx 1 root root 0 Mar 21 11:47 MyPFXCertificate.key.nopass.pem
-rwxrwxrwx 1 root root 0 Mar 21 11:47 MyPFXCertificate.cert.chained.pem
-rwxrwxrwx 1 root root 0 Mar 21 11:47 MyPFXCertificate.cert.pem
-rwxrwxrwx 1 root root 0 Mar 21 11:47 MyPFXCertificate.combined.pem
convertcert.sh 586 B
#!/bin/bash
pfx=$1
out=${pfx%.pfx}
# Create a private keyfile (with password)
openssl pkcs12 -in "$pfx" -out "$out.key.pem"
# Create the private keyfile (without password)
openssl pkcs12 -in "$pfx" -out "$out.key.nopass.pem" -nocerts -clcerts -nodes
# Create the public key with the chain
openssl pkcs12 -in "$pfx" -out "$out.cert.chained.pem" -nokeys
# Create the public key without the chain
openssl pkcs12 -in "$pfx" -out "$out.cert.nochain.pem" -clcerts -nokeys
# Create a combined cert/key (for haproxy)
cat "$out.cert.chained.pem" "$out.key.nopass.pem" > "$out.combined.pem"
Please register or sign in to comment