Web Crypto
subtle.verify()
Checks whether a signature or MAC matches the supplied bytes. A false result must not authorize the request. Tested on Node.js 22.16.0. Example output (one line per entry): ["true false"].
Formal Syntax & Structure
nodejs syntaxnodejs
subtle.verify(algorithm, key, signature, data)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| algorithm | string | object | Verification algorithm. |
| key | CryptoKey | Verification key. |
| signature | BufferSource | Signature or MAC. |
| data | BufferSource | Message bytes. |
Return Value
Promise<boolean>
Verification result.
Working Example
Example Snippetnodejs
import { webcrypto as crypto } from 'node:crypto';const k = await crypto.subtle.generateKey({ name: 'HMAC', hash: 'SHA-256' }, false, ['sign', 'verify']);const p = new Uint8Array([7]);const mac = await crypto.subtle.sign('HMAC', k, p);console.log(await crypto.subtle.verify('HMAC', k, mac, p), await crypto.subtle.verify('HMAC', k, mac, new Uint8Array([8])));