Aller au contenu

Référence de l'API node:crypto

Hachage, chiffrements, clés, signatures, accord de clés et données aléatoires

Sur cette page
import { createHash, randomUUID } from "node:crypto";

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

Surface prise en charge

  • Hachage et HMAC : createHash, createHmac, hash, getHashes
  • Chiffrements : createCipheriv, createDecipheriv, getCiphers, getCipherInfo (AES CBC, CTR, ECB, CFB, OFB, GCM, CCM et key wrap ; ChaCha20 et ChaCha20-Poly1305 ; 3DES)
  • Clés : KeyObject, createSecretKey, createPublicKey, createPrivateKey, avec import et export PEM, DER (PKCS#1, PKCS#8, SPKI, SEC1, PKCS#8 chiffré et ancien PEM chiffré) et JWK
  • Génération de clés : generateKeyPair, generateKeyPairSync, generateKey, generateKeySync pour RSA, RSA-PSS, DSA, EC, Ed25519, X25519, DH, ML-DSA et ML-KEM
  • Signatures : sign, verify, createSign, createVerify (PKCS#1 v1.5, PSS, encodages ECDSA/DSA DER et IEEE-P1363)
  • Chiffrement RSA : publicEncrypt, privateDecrypt, privateEncrypt, publicDecrypt
  • Accord de clés : createDiffieHellman, getDiffieHellman, createECDH, ECDH.convertKey, diffieHellman, getCurves
  • Dérivation et nombres premiers : hkdf, pbkdf2, scrypt, generatePrime, checkPrime
  • Données aléatoires : randomBytes, randomFill, randomInt, randomUUID
  • timingSafeEqual, constants et webcrypto (le même objet que globalThis.crypto)

La cryptographie d’Elide repose sur AWS-LC, un fork de BoringSSL, et se présente comme le fait Node lorsqu’il est compilé avec BoringSSL : process.versions.openssl vaut 1.1.1 et process.features.openssl_is_boringssl vaut true. Les échecs portent les chaînes d’erreur d’AWS-LC (par exemple error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT) avec library, reason et un code ERR_OSSL_*. Ed448, X448 et OCB ne sont pas disponibles ; le mode FIPS ne peut pas être activé.

Consultez la documentation crypto de Node.js pour les formes d’arguments standard.

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.

Cette page vous a-t-elle aidé ?