crypto.hkdfSync(digest, ikm, salt, info, keylen)


提供一个同步的 HKDF 密钥派生函数,如 RFC 5869 所定义。给定的 ikmsaltinfodigest 一起使用,以派生 keylen 字节的密钥。

【Provides a synchronous HKDF key derivation function as defined in RFC 5869. The given ikm, salt and info are used with the digest to derive a key of keylen bytes.】

成功生成的 derivedKey 将作为 <ArrayBuffer> 返回。

【The successfully generated derivedKey will be returned as an <ArrayBuffer>.】

如果任何输入参数指定了无效的值或类型,或者无法生成派生密钥,将会抛出错误。

【An error will be thrown if any of the input arguments specify invalid values or types, or if the derived key cannot be generated.】

import { Buffer } from 'node:buffer';
const {
  hkdfSync,
} = await import('node:crypto');

const derivedKey = hkdfSync('sha512', 'key', 'salt', 'info', 64);
console.log(Buffer.from(derivedKey).toString('hex'));  // '24156e2...5391653'const {
  hkdfSync,
} = require('node:crypto');
const { Buffer } = require('node:buffer');

const derivedKey = hkdfSync('sha512', 'key', 'salt', 'info', 64);
console.log(Buffer.from(derivedKey).toString('hex'));  // '24156e2...5391653'