Crypto
crypto.sign()
Produces a digital signature over bytes. A signature is not confidentiality. Ed25519 selects its own hashing behavior, so the algorithm argument is null for that key type. Tested on Node.js 22.16.0. Example output (one line per entry): ["true"].
Formal Syntax & Structure
nodejs syntaxnodejs
crypto.sign(algorithm, data, key[, callback])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| algorithm | string | null | Algorithm selector. |
| data | Buffer | TypedArray | DataView | Message bytes. |
| key | KeyObject | object | Signing key and options. |
| callback | Function | Optional asynchronous completion. |
Return Value
Buffer | undefined
Signature or callback result.
Working Example
Example Snippetnodejs
import { generateKeyPairSync, sign, verify } from 'node:crypto';const { privateKey, publicKey } = generateKeyPairSync('ed25519');const msg = Buffer.from('book:approved'), sig = sign(null, msg, privateKey);console.log(verify(null, msg, publicKey, sig));