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

NameTypeDescription
algorithmstring | nullAlgorithm selector.
dataBuffer | TypedArray | DataViewMessage bytes.
keyKeyObject | objectSigning key and options.
callbackFunctionOptional 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));
Node.js Reference