import { createHash, randomUUID } from "node:crypto";
console.log(createHash("sha256").update("abc").digest("hex"));
console.log(randomUUID());Superficie admitida
- Hashing y HMAC:
createHash,createHmac,hash,getHashes - Cifrados:
createCipheriv,createDecipheriv,getCiphers,getCipherInfo(AES CBC, CTR, ECB, CFB, OFB, GCM, CCM y key wrap; ChaCha20 y ChaCha20-Poly1305; 3DES) - Claves:
KeyObject,createSecretKey,createPublicKey,createPrivateKey, con importación y exportación en PEM, DER (PKCS#1, PKCS#8, SPKI, SEC1, PKCS#8 cifrado y PEM cifrado heredado) y JWK - Generación de claves:
generateKeyPair,generateKeyPairSync,generateKey,generateKeySyncpara RSA, RSA-PSS, DSA, EC, Ed25519, X25519, DH, ML-DSA y ML-KEM - Firmas:
sign,verify,createSign,createVerify(PKCS#1 v1.5, PSS, y codificaciones DER e IEEE-P1363 de ECDSA/DSA) - Cifrado RSA:
publicEncrypt,privateDecrypt,privateEncrypt,publicDecrypt - Acuerdo de claves:
createDiffieHellman,getDiffieHellman,createECDH,ECDH.convertKey,diffieHellman,getCurves - Derivación y números primos:
hkdf,pbkdf2,scrypt,generatePrime,checkPrime - Datos aleatorios:
randomBytes,randomFill,randomInt,randomUUID timingSafeEqual,constantsywebcrypto(el mismo objeto queglobalThis.crypto)
La criptografía de Elide se basa en AWS-LC, una bifurcación de BoringSSL, y se identifica igual que Node
cuando se compila con BoringSSL: process.versions.openssl es 1.1.1 y
process.features.openssl_is_boringssl es true. Los fallos llevan las cadenas de error de AWS-LC (por
ejemplo error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT) con library, reason
y un código ERR_OSSL_*. Ed448, X448 y OCB no están disponibles; no se puede activar el modo FIPS.
Consulte la documentación de crypto de Node.js para ver las formas estándar de los argumentos.
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.