openssl dgst -sha256 -verify pub.pem -signature sig.der message.txt# "Verified OK" (exit 0) or "Verification failure" (exit 1)# derive the public key from a private keyopenssl pkey -in key.pem -pubout -out pub.pem # or extract it from a certificateopenssl x509 -in cert.pem -pubkey -noout > pub.pemopenssl asn1parse -inform DER -in sig.der# a well-formed ECDSA signature shows: SEQUENCE, INTEGER (r), INTEGER (s)How it works
-sha256must repeat the hash the signer used — OpenSSL cannot infer it from the signature bytes.-verifytakes the public key; the similarly named-prverifyverifies using a private key by deriving its public half.- The exit code mirrors the verdict (
0verified,1failure), which makes the command easy to use in scripts and CI.
Gotchas
dgstconsumes only DER signatures. A 64-byte raw r‖s signature (WebCrypto, JWS) fails withasn1 encoding routineserrors — convert it to DER first; the browser converter does this without any code.openssl dgst -sha256 message.txtalone just prints a hash — verification requires both-verifyand-signature.- A wrong key file fails identically to a corrupted signature. When in doubt, re-derive the public key from the signer's private key and diff the two PEMs.