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
| Name | Type | Description |
|---|---|---|
| algorithm | string | null | Algorithm selector. |
| data | Buffer | TypedArray | DataView | Original message bytes. |
| key | KeyObject | object | Verification key. |
| signature | Buffer | TypedArray | DataView | Signature bytes. |
| callback | Function | Optional 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));