| name | OpenSSL |
| description | Expert guidance for OpenSSL operations including certificate generation, key management, CSR creation, certificate verification, encryption, and PKI operations. Use this when working with SSL/TLS certificates, cryptographic keys, or PKI infrastructure. |
OpenSSL
Expert assistance with OpenSSL cryptographic operations and PKI management.
Key Generation
RSA Keys
openssl genrsa -out private.key 2048
openssl genrsa -out private.key 4096
openssl genrsa -aes256 -out private.key 4096
openssl rsa -in private.key -pubout -out public.key
openssl rsa -in encrypted.key -out decrypted.key
EC (Elliptic Curve) Keys
openssl ecparam -list_curves
openssl ecparam -name prime256v1 -genkey -noout -out ec-private.key
openssl ecparam -name secp384r1 -genkey -noout -out ec-private.key
openssl ec -in ec-private.key -pubout -out ec-public.key
Certificate Signing Requests (CSR)
Create CSR
openssl req -new -key private.key -out request.csr
openssl req -new -key private.key -out request.csr \
-subj "/C=US/ST=State/L=City/O=Organization/CN=example.com"
openssl req -newkey rsa:2048 -nodes -keyout private.key -out request.csr
openssl req -new -key private.key -out request.csr -config san.cnf
SAN Configuration File (san.cnf)
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
[req_distinguished_name]
CN = example.com
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = example.com
DNS.2 = www.example.com
DNS.3 = api.example.com
IP.1 = 192.168.1.1
View CSR
openssl req -in request.csr -noout -text
openssl req -in request.csr -noout -verify
Self-Signed Certificates
Create Self-Signed Certificate
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365
openssl req -x509 -key private.key -out cert.pem -days 365
openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 \
-subj "/C=US/ST=State/L=City/O=Org/CN=example.com"
Certificate Authority (CA) Operations
Create Root CA
openssl genrsa -aes256 -out ca-key.pem 4096
openssl req -x509 -new -nodes -key ca-key.pem -sha256 -days 3650 \
-out ca-cert.pem -subj "/C=US/O=MyOrg/CN=MyOrg Root CA"
Sign Certificate with CA
openssl x509 -req -in request.csr -CA ca-cert.pem -CAkey ca-key.pem \
-CAcreateserial -out cert.pem -days 365 -sha256
openssl x509 -req -in request.csr -CA ca-cert.pem -CAkey ca-key.pem \
-CAcreateserial -out cert.pem -days 365 -sha256 -extensions v3_req -extfile san.cnf
Create Intermediate CA
openssl genrsa -aes256 -out intermediate-key.pem 4096
openssl req -new -key intermediate-key.pem -out intermediate.csr
openssl x509 -req -in intermediate.csr -CA ca-cert.pem -CAkey ca-key.pem \
-CAcreateserial -out intermediate-cert.pem -days 1825 -sha256
cat intermediate-cert.pem ca-cert.pem > chain.pem
Certificate Inspection & Verification
View Certificate Details
openssl x509 -in cert.pem -noout -text
openssl x509 -in cert.pem -noout -subject
openssl x509 -in cert.pem -noout -issuer
openssl x509 -in cert.pem -noout -dates
openssl x509 -in cert.pem -noout -serial
openssl x509 -in cert.pem -noout -fingerprint
openssl x509 -in cert.pem -noout -enddate
openssl x509 -in cert.pem -text -noout
Verify Certificates
openssl verify -CAfile ca-cert.pem cert.pem
openssl verify -CAfile ca-cert.pem -untrusted intermediate-cert.pem cert.pem
openssl x509 -noout -modulus -in cert.pem | openssl md5
openssl rsa -noout -modulus -in private.key | openssl md5
Test SSL/TLS Connection
openssl s_client -connect example.com:443 -showcerts
openssl s_client -connect example.com:443 -tls1_2
openssl s_client -connect example.com:443 -tls1_3
openssl s_client -connect example.com:443 -servername example.com
echo | openssl s_client -connect example.com:443 2>/dev/null | \
openssl x509 -noout -dates
Format Conversion
PEM ↔ DER
openssl x509 -in cert.pem -outform DER -out cert.der
openssl x509 -in cert.der -inform DER -out cert.pem -outform PEM
PKCS#12 (PFX)
openssl pkcs12 -export -out cert.pfx -inkey private.key -in cert.pem
openssl pkcs12 -export -out cert.pfx -inkey private.key -in cert.pem -certfile chain.pem
openssl pkcs12 -in cert.pfx -out cert-and-key.pem -nodes
openssl pkcs12 -in cert.pfx -clcerts -nokeys -out cert.pem
openssl pkcs12 -in cert.pfx -nocerts -nodes -out private.key
PKCS#7
openssl crl2pkcs7 -nocrl -certfile cert.pem -out cert.p7b
openssl pkcs7 -print_certs -in cert.p7b -out cert.pem
Encryption & Decryption
Symmetric Encryption
openssl enc -aes-256-cbc -salt -in file.txt -out file.enc
openssl enc -aes-256-cbc -d -in file.enc -out file.txt
openssl enc -aes-256-cbc -salt -in file.txt -out file.enc -pass file:password.txt
openssl enc -aes-256-cbc -salt -in file.txt -out file.enc -a
Asymmetric Encryption
openssl rsautl -encrypt -pubin -inkey public.key -in file.txt -out file.enc
openssl rsautl -decrypt -inkey private.key -in file.enc -out file.txt
Hashing & Digests
openssl dgst -sha256 file.txt
openssl dgst -sha512 file.txt
openssl dgst -md5 file.txt
openssl dgst -sha256 -sign private.key -out signature.bin file.txt
openssl dgst -sha256 -verify public.key -signature signature.bin file.txt
openssl dgst -sha256 -hmac "secret-key" file.txt
Certificate Revocation
Create Certificate Revocation List (CRL)
openssl ca -gencrl -config crl.cnf -out crl.pem
openssl crl -in crl.pem -text -noout
openssl verify -crl_check -CRLfile crl.pem -CAfile ca-cert.pem cert.pem
OCSP (Online Certificate Status Protocol)
openssl ocsp -port 8080 -index index.txt -CA ca-cert.pem -rkey ca-key.pem -rsigner ca-cert.pem
openssl ocsp -issuer ca-cert.pem -cert cert.pem -url http://ocsp.example.com:8080
Common PKI Workflows
Complete Certificate Workflow
openssl genrsa -out server.key 4096
openssl req -new -key server.key -out server.csr \
-subj "/C=US/ST=CA/L=SF/O=MyOrg/CN=example.com"
openssl x509 -req -in server.csr -CA ca-cert.pem -CAkey ca-key.pem \
-CAcreateserial -out server.crt -days 365 -sha256
openssl verify -CAfile ca-cert.pem server.crt
openssl s_server -cert server.crt -key server.key -accept 8443
Best Practices
- Key Size: Use at least 2048-bit RSA or 256-bit EC keys
- Hash Algorithm: Use SHA-256 or stronger (avoid MD5, SHA-1)
- Validity Period: Certificates should be valid for ≤ 398 days (current CA/Browser Forum baseline)
- Private Key Protection: Always encrypt private keys with strong passphrases
- SAN: Always include Subject Alternative Names, even for single domain
- Key Backup: Securely backup private keys and CA certificates
- Certificate Chain: Always provide complete certificate chain
- Regular Rotation: Rotate certificates before expiration
Security Notes
- Never share private keys - They should remain on the server
- Use strong passphrases for encrypted keys (16+ characters)
- Protect CA keys with HSM or secure key storage
- Monitor expiration - Set up alerts 30 days before expiry
- Revoke compromised certificates immediately
- Use Certificate Transparency for public certificates