Zum Inhalt springen

API-Referenz zu node:crypto

Hashing, Chiffren, Schlüssel, Signaturen, Schlüsselvereinbarung und Zufallsdaten

Auf dieser Seite
import { createHash, randomUUID } from "node:crypto";

console.log(createHash("sha256").update("abc").digest("hex"));
console.log(randomUUID());

Unterstützter Umfang

  • Hashing und HMAC: createHash, createHmac, hash, getHashes
  • Chiffren: createCipheriv, createDecipheriv, getCiphers, getCipherInfo (AES CBC, CTR, ECB, CFB, OFB, GCM, CCM und Key Wrap; ChaCha20 und ChaCha20-Poly1305; 3DES)
  • Schlüssel: KeyObject, createSecretKey, createPublicKey, createPrivateKey, mit Import und Export von PEM, DER (PKCS#1, PKCS#8, SPKI, SEC1, verschlüsseltes PKCS#8 und veraltetes verschlüsseltes PEM) und JWK
  • Schlüsselerzeugung: generateKeyPair, generateKeyPairSync, generateKey, generateKeySync für RSA, RSA-PSS, DSA, EC, Ed25519, X25519, DH, ML-DSA und ML-KEM
  • Signaturen: sign, verify, createSign, createVerify (PKCS#1 v1.5, PSS, DER- und IEEE-P1363-Kodierungen für ECDSA/DSA)
  • RSA-Verschlüsselung: publicEncrypt, privateDecrypt, privateEncrypt, publicDecrypt
  • Schlüsselvereinbarung: createDiffieHellman, getDiffieHellman, createECDH, ECDH.convertKey, diffieHellman, getCurves
  • Ableitung und Primzahlen: hkdf, pbkdf2, scrypt, generatePrime, checkPrime
  • Zufallsdaten: randomBytes, randomFill, randomInt, randomUUID
  • timingSafeEqual, constants und webcrypto (dasselbe Objekt wie globalThis.crypto)

Die Kryptografie von Elide läuft auf AWS-LC, einem Fork von BoringSSL, und meldet sich so, wie Node es tut, wenn es gegen BoringSSL gebaut ist: process.versions.openssl ist 1.1.1 und process.features.openssl_is_boringssl ist true. Fehler tragen die Fehlerzeichenketten von AWS-LC (zum Beispiel error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT) mit library, reason und einem ERR_OSSL_*-Code. Ed448, X448 und OCB sind nicht verfügbar; der FIPS-Modus kann nicht aktiviert werden.

Die üblichen Argumentformen finden Sie in der Node.js-Dokumentation zu crypto.

Reference

Status: Partial · 95 of 112 suite tests pass (84.8%) · since 1.1.0

Exports

ExportKindStatusNotes
HashclassFullupdate(), digest(), copy()
HmacclassFullupdate(), digest()
createHash()functionFullCreates and returns a Hash object for the given algorithm
createHmac()functionFullCreates and returns an Hmac object for the given algorithm and key
randomBytes()functionFullGenerates cryptographically strong pseudorandom bytes
randomFill(), randomFillSync()functionFullFills a buffer with random bytes
randomInt()functionFullReturns a random integer n such that min <= n < max
randomUUID()functionFullGenerates a random RFC 4122 version 4 UUID string
pbkdf2(), pbkdf2Sync()functionFullDerives a key using PBKDF2
scrypt(), scryptSync()functionFullDerives a key using scrypt
timingSafeEqual()functionFullCompares two buffers in constant time to prevent timing attacks
getHashes()functionFullReturns the list of supported hash algorithm names
getCiphers()functionFullReturns the list of supported cipher algorithm names
constantspropertyFullCrypto constants such as RSA_PKCS1_PADDING
webcryptopropertyFullThe Web Crypto API (SubtleCrypto) instance

Not implemented

Certificate, X509Certificate, decapsulate, encapsulate.

Tests: node-api node:crypto: 95 pass, 17 fail, 0 error, 69 skipped. Failing: test-crypto-certificate.js, test-crypto-dh-leak.js, test-crypto-encap-decap.js, test-crypto-key-objects-messageport.js, test-crypto-keyobject-hidden-slots.js, test-crypto-pqc-encrypted-pkcs8.js, test-crypto-pqc-key-objects-ml-dsa.js, test-crypto-pqc-key-objects-ml-kem.js, and 9 more.

War diese Seite hilfreich?