Crypto

crypto.verify()

Checks a signature against data and a verification key. Trust in that public key must be established separately. Reject altered content before acting on it. Tested on Node.js 22.16.0. Example output (one line per entry): ["true false"].

Formal Syntax & Structure

nodejs syntaxnodejs
crypto.verify(algorithm, data, key, signature[, callback])

Parameters & Attributes

NameTypeDescription
algorithmstring | nullAlgorithm selector.
dataBuffer | TypedArray | DataViewOriginal message bytes.
keyKeyObject | objectVerification key.
signatureBuffer | TypedArray | DataViewSignature bytes.
callbackFunctionOptional completion callback.

Return Value

boolean | undefined

Verification result or callback completion.

Working Example

Example Snippetnodejs
import { generateKeyPairSync, sign, verify } from 'node:crypto';const { privateKey, publicKey } = generateKeyPairSync('ed25519');const sig = sign(null, Buffer.from('count:1'), privateKey);console.log(verify(null, Buffer.from('count:1'), publicKey, sig), verify(null, Buffer.from('count:2'), publicKey, sig));
Node.js Reference