OpenSSL provides cryptographic primitives, protocol libraries, and command-line tools. Commands are useful for inspection, interoperability tests, and local administration; application code should use a maintained language library and its safe defaults.
Keys, CSRs, and Certificates #
Generate a private key with the generic key interface:
openssl genpkey -algorithm RSA \
-pkeyopt rsa_keygen_bits:3072 \
-out private-key.pem
openssl pkey -in private-key.pem -pubout -out public-key.pemCreate a certificate-signing request and inspect it:
openssl req -new -key private-key.pem -out request.csr
openssl req -in request.csr -noout -text -verify
openssl x509 -in certificate.pem -noout -textreq -verify checks the CSR’s proof of possession. It does not validate the
requested identity or issue a certificate. A CSR contains a public key and
request attributes, never the private key.
Verify a certificate path against an explicit trust store:
openssl verify -CAfile roots.pem -untrusted intermediate.pem certificate.pemPEM wraps a DER object in base64 text with type markers. Convert explicitly and retain the object type:
openssl x509 -in certificate.pem -outform DER -out certificate.der
openssl x509 -inform DER -in certificate.der -out certificate.pem
openssl pkey -in private-key.pem -outform DER -out private-key.derTLS clients also require hostname verification. For a diagnostic connection, pass the expected server name and verification options:
openssl s_client -connect example.com:443 \
-servername example.com -verify_hostname example.comDigests and Signatures #
openssl dgst -sha256 artifact.tar
openssl rand -hex 32
openssl dgst -sha256 -sign private-key.pem -out artifact.sig artifact.tar
openssl dgst -sha256 -verify public-key.pem -signature artifact.sig artifact.tarA digest detects accidental changes only when its expected value arrives through an authenticated channel. A signature verifies both the digest and possession of the corresponding private key, but trust in the public key remains a separate deployment decision.
Password-Based Encryption #
openssl enc -aes-256-cbc -pbkdf2 -salt \
-in plaintext -out ciphertextopenssl enc does not provide modern AEAD modes through its traditional
interface. Do not use it to invent an application encryption protocol. Use a
specified AEAD format or a dedicated tool for files requiring authenticated
encryption. When interoperability requires enc, state the digest and iteration
count explicitly because defaults can change, and understand that CBC ciphertext
remains unauthenticated.
Pass secrets through protected files or descriptors where the command supports them. A password written as a command argument can appear in process listings and shell history. Restrict private-key permissions and remove temporary plaintext only through storage-appropriate procedures.
TLS Diagnostics #
s_client is a diagnostic client rather than a policy-complete replacement for
an application. Add -showcerts, -verify_return_error, and the application’s
expected protocol options when investigating path or handshake failures:
openssl s_client -connect example.com:443 -servername example.com \
-verify_hostname example.com -verify_return_error -showcertsAvoid deprecated commands such as rsautl in new automation; pkeyutl and
genpkey expose current interfaces. Inspect locally installed documentation
with openssl list -commands and openssl list -providers because providers,
algorithms, and defaults vary by OpenSSL release.
Comments
Read or comment on GitHub (sign-in required to comment)