网络加密 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 |
| v19.0.0 | No longer experimental except for the |
| 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 |
| v18.4.0, v16.17.0 | Removed proprietary |
| v18.4.0, v16.17.0 | Added |
| v18.4.0, v16.17.0 | Removed proprietary |
| v18.4.0, v16.17.0 | Removed proprietary |
Node.js 提供了 网络加密 API 标准的实现。
🌐 Node.js provides an implementation of the Web Crypto API standard.
使用 globalThis.crypto 或 require('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);
})();