网络加密 API


🌐 Web Crypto API

版本历史
版本变更
v25.9.0

TurboSHAKE and KangarooTwelve algorithms are now supported.

v24.8.0

KMAC algorithms are now supported.

v24.8.0

Argon2 algorithms are now supported.

v24.7.0

AES-OCB algorithm is now supported.

v24.7.0

ML-KEM algorithms are now supported.

v24.7.0

ChaCha20-Poly1305 algorithm is now supported.

v24.7.0

SHA-3 algorithms are now supported.

v24.7.0

SHAKE algorithms are now supported.

v24.7.0

ML-DSA algorithms are now supported.

v23.5.0, v22.13.0, v20.19.3

Algorithms Ed25519 and X25519 are now stable.

v19.0.0

No longer experimental except for the Ed25519, Ed448, X25519, and X448 algorithms.

v20.0.0, v18.17.0

Arguments are now coerced and validated as per their WebIDL definitions like in other Web Crypto API implementations.

v18.4.0, v16.17.0

Removed proprietary 'node.keyObject' import/export format.

v18.4.0, v16.17.0

Removed proprietary 'NODE-DSA', 'NODE-DH', and 'NODE-SCRYPT' algorithms.

v18.4.0, v16.17.0

Added 'Ed25519', 'Ed448', 'X25519', and 'X448' algorithms.

v18.4.0, v16.17.0

Removed proprietary 'NODE-ED25519' and 'NODE-ED448' algorithms.

v18.4.0, v16.17.0

Removed proprietary 'NODE-X25519' and 'NODE-X448' named curves from the 'ECDH' algorithm.

稳定性: 2 - 稳定

Node.js 提供了 网络加密 API 标准的实现。

🌐 Node.js provides an implementation of the Web Crypto API standard.

使用 globalThis.cryptorequire('node:crypto').webcrypto 来访问此模块。

🌐 Use globalThis.crypto or require('node:crypto').webcrypto to access this module.

const { subtle } = globalThis.crypto;
(async function() {
 const key = await subtle.generateKey({
 name: 'HMAC',
 hash: 'SHA-256',
 length: 256,
 }, true, ['sign', 'verify']);
 const enc = new TextEncoder();
 const message = enc.encode('I love cupcakes');
 const digest = await subtle.sign({
 name: 'HMAC',
 }, key, message);
})(); 

AltStyle によって変換されたページ (->オリジナル) /