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,generateKeySyncpour 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,constantsetwebcrypto(le même objet queglobalThis.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
| Export | Kind | Status | Notes |
|---|---|---|---|
Hash | class | Full | update(), digest(), copy() |
Hmac | class | Full | update(), digest() |
createHash() | function | Full | Creates and returns a Hash object for the given algorithm |
createHmac() | function | Full | Creates and returns an Hmac object for the given algorithm and key |
randomBytes() | function | Full | Generates cryptographically strong pseudorandom bytes |
randomFill(), randomFillSync() | function | Full | Fills a buffer with random bytes |
randomInt() | function | Full | Returns a random integer n such that min <= n < max |
randomUUID() | function | Full | Generates a random RFC 4122 version 4 UUID string |
pbkdf2(), pbkdf2Sync() | function | Full | Derives a key using PBKDF2 |
scrypt(), scryptSync() | function | Full | Derives a key using scrypt |
timingSafeEqual() | function | Full | Compares two buffers in constant time to prevent timing attacks |
getHashes() | function | Full | Returns the list of supported hash algorithm names |
getCiphers() | function | Full | Returns the list of supported cipher algorithm names |
constants | property | Full | Crypto constants such as RSA_PKCS1_PADDING |
webcrypto | property | Full | The 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.