Skip to content

Instantly share code, notes, and snippets.

@joshkitt
Last active August 14, 2024 16:53
Show Gist options
  • Save joshkitt/c40816a7d1443cf73be5e7ae47ed6fb1 to your computer and use it in GitHub Desktop.
Save joshkitt/c40816a7d1443cf73be5e7ae47ed6fb1 to your computer and use it in GitHub Desktop.
Extract certificate key, certificate, and certificate chain from a pfx tls certificate file
openssl pkcs12 -in cert.pfx -nocerts -nodes | sed -ne '/-BEGIN PRIVATE KEY-/,/-END PRIVATE KEY-/p' > cert.key
openssl pkcs12 -in cert.pfx -clcerts -nokeys | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > cert.cer
openssl pkcs12 -in cert.pfx -cacerts -nokeys -chain | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > chain.cer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment