Skip to content

Instantly share code, notes, and snippets.

@dejanstojanovic
Last active April 16, 2024 04:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dejanstojanovic/bce1c92ccbb9352e102dc32a3d91f8fa to your computer and use it in GitHub Desktop.
Save dejanstojanovic/bce1c92ccbb9352e102dc32a3d91f8fa to your computer and use it in GitHub Desktop.
Common OpenSSL commands

Common openssl commands

Create CSR

openssl req -nodes -newkey rsa:2048 -nodes -keyout privateKey.key -out CertRequest.csr -subj "/CN=mydomain.com"

Generate self-sign certificate

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt

Generate CSR from existing private KEY

openssl req -out CertRequest.csr -key privateKey.key -new

using existing certificate

openssl x509 -x509toreq -in certificate.crt -out CertRequest.csr -signkey privateKey.key

Convert PEM to DER

openssl x509 -outform der -in certificate.pem -out certificate.der

Convert CER to P7B

openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b

Convert CER to PEM

openssl x509 -inform der -in certificate.cer -out certificate.pem

Convert P7B to CER

openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

Convert CER to PFX

openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx

Convert CRT to PFX

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt

using intermediate certificate

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

Convert PFX to CER

openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes

Cnvert CRT to PFX

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment