OpenSSL 3 cheatsheet
OpenSSL 3: Converting, hashing and encrypting
9 common OpenSSL 3 tasks.
Convert PEM to DER
Convert a certificate between text (PEM) and binary (DER) encodings.
openssl x509 -in cert.pem -outform DER -out cert.der
Bundle a key and certificate as PKCS#12
Create a .p12 or .pfx file, for example for Windows or Java. You are prompted for a password.
openssl pkcs12 -export -inkey private.key -in cert.pem -out bundle.p12
Extract from a PKCS#12 bundle
Extract the certificate and key from a bundle as PEM.
openssl pkcs12 -in bundle.p12 -nodes -out all.pem
Generate random bytes
Print 32 random bytes as 64 hex characters, suitable for a secret key.
openssl rand -hex 32
Encrypt a file with a password
Encrypt with AES-256 and a key derived from the password. You are prompted for it.
openssl enc -aes-256-cbc -pbkdf2 -salt -in secret.txt -out secret.enc
Decrypt a file
Reverse the encryption above with the same password.
openssl enc -d -aes-256-cbc -pbkdf2 -in secret.enc -out secret.txt
Sign and verify a file
Create a signature with a private key, then check it with the public key.
openssl dgst -sha256 -sign private.key -out file.sig file.txt
openssl dgst -sha256 -verify public.key -signature file.sig file.txt