openssl Commands

Security

Check SSL Certificate

Check SSL certificate validity

openssl x509 -in certificate.crt -text -noout

Key Generation

openssl genrsa

Generate RSA private key.

openssl genrsa

Examples:
Generate 2048-bit RSA private key
openssl genrsa -out private.key 2048
Generate encrypted private key
openssl genrsa -des3 -out private.key 2048

Certificate Management

openssl req

Generate certificate signing request (CSR).

openssl req

Examples:
Generate CSR with private key
openssl req -new -key private.key -out request.csr
Generate CSR with config file
openssl req -new -key private.key -out request.csr -config openssl.cnf
openssl x509

Certificate display and signing utility.

openssl x509

Examples:
View certificate details
openssl x509 -in certificate.crt -text -noout
Check certificate dates
openssl x509 -in certificate.crt -dates -noout
openssl verify

Verify certificate chain.

openssl verify

Examples:
Verify certificate
openssl verify certificate.crt
Verify with CA bundle
openssl verify -CAfile ca-bundle.crt certificate.crt

Keystore Management

openssl pkcs12

PKCS#12 file utility for creating and managing keystores.

openssl pkcs12

Examples:
Create PKCS#12 keystore
openssl pkcs12 -export -in certificate.crt -inkey private.key -out keystore.p12
View PKCS#12 contents
openssl pkcs12 -in keystore.p12 -info -noout

Ssl/tls Testing

openssl s_client

SSL/TLS client program for testing connections.

openssl s_client

Examples:
Test SSL connection
openssl s_client -connect example.com:443
Test with SNI
openssl s_client -connect example.com:443 -servername example.com
Show certificate chain
openssl s_client -connect example.com:443 -showcerts
openssl s_server

SSL/TLS server program for testing.

openssl s_server

Examples:
Start SSL server
openssl s_server -cert server.crt -key server.key -port 8443

Encryption

openssl enc

Encrypt or decrypt files using various algorithms.

openssl enc

Examples:
Encrypt file with AES
openssl enc -aes-256-cbc -in file.txt -out file.enc
Decrypt file
openssl enc -aes-256-cbc -d -in file.enc -out file.txt

Random Generation

openssl rand

Generate random bytes.

openssl rand

Examples:
Generate random bytes
openssl rand -out random.bin 32
Generate random hex string
openssl rand -hex 32
Generate random base64
openssl rand -base64 32

Hashing

openssl dgst

Generate message digest (hash) of files.

openssl dgst

Examples:
Generate SHA256 hash
openssl dgst -sha256 file.txt
Generate MD5 hash
openssl dgst -md5 file.txt