node:crypto
#Import
import crypto from "nstdlib/node/crypto";Note
Behaves like Node.js. Randomness, timingSafeEqual and subtle run on the host WebCrypto. createHash/createHmac/hash()/pbkdf2/hkdf are computed in JavaScript for MD5, SHA-1, SHA-2, SHA-3 and the SHAKEs. Ciphers, keys, signing and scrypt need OpenSSL and throw.
#Support
- nstd: Gives the same output as Node.js in side-by-side tests: digest.
- Browser: Loads with a minimal
processobject. 77 of Node's 77 exports are available. 0 of 1 behavior checks match Node.js. Didn't match: crypto: randomness, WebCrypto, the digests and the OpenSSL half (a known difference).
#Exports (77)
Every name Node.js exports from this module, and what you get when you read it, as a named import or as a property of the default import:
- ✅ A value, both ways. An export that throws an error naming the missing feature also counts.
- ⚠️ A value one way,
undefinedthe other. - ❔
undefinedboth ways. - ❌ Not exported at all.
- – Not measured.
Show all 77 exports
| Export | Node.js | Browser |
|---|---|---|
Certificate | ✅ | ✅ |
Cipheriv | ✅ | ✅ |
Decipheriv | ✅ | ✅ |
DiffieHellman | ✅ | ✅ |
DiffieHellmanGroup | ✅ | ✅ |
ECDH | ✅ | ✅ |
Hash | ✅ | ✅ |
Hmac | ✅ | ✅ |
KeyObject | ✅ | ✅ |
Sign | ✅ | ✅ |
Verify | ✅ | ✅ |
X509Certificate | ✅ | ✅ |
argon2 | ✅ | ✅ |
argon2Sync | ✅ | ✅ |
checkPrime | ✅ | ✅ |
checkPrimeSync | ✅ | ✅ |
constants | ✅ | ✅ |
createCipheriv | ✅ | ✅ |
createDecipheriv | ✅ | ✅ |
createDiffieHellman | ✅ | ✅ |
createDiffieHellmanGroup | ✅ | ✅ |
createECDH | ✅ | ✅ |
createHash | ✅ | ✅ |
createHmac | ✅ | ✅ |
createMac | ✅ | ✅ |
createPrivateKey | ✅ | ✅ |
createPublicKey | ✅ | ✅ |
createSecretKey | ✅ | ✅ |
createSign | ✅ | ✅ |
createVerify | ✅ | ✅ |
decapsulate | ✅ | ✅ |
diffieHellman | ✅ | ✅ |
encapsulate | ✅ | ✅ |
fips | ✅ | ✅ |
generateKey | ✅ | ✅ |
generateKeyPair | ✅ | ✅ |
generateKeyPairSync | ✅ | ✅ |
generateKeySync | ✅ | ✅ |
generatePrime | ✅ | ✅ |
generatePrimeSync | ✅ | ✅ |
getCipherInfo | ✅ | ✅ |
getCiphers | ✅ | ✅ |
getCurves | ✅ | ✅ |
getDiffieHellman | ✅ | ✅ |
getFips | ✅ | ✅ |
getHashes | ✅ | ✅ |
getMacs | ✅ | ✅ |
getRandomValues | ✅ | ✅ |
hash | ✅ | ✅ |
hkdf | ✅ | ✅ |
hkdfSync | ✅ | ✅ |
parsePKCS12 | ✅ | ✅ |
pbkdf2 | ✅ | ✅ |
pbkdf2Sync | ✅ | ✅ |
privateDecrypt | ✅ | ✅ |
privateEncrypt | ✅ | ✅ |
prng | ✅ | ✅ |
pseudoRandomBytes | ✅ | ✅ |
publicDecrypt | ✅ | ✅ |
publicEncrypt | ✅ | ✅ |
randomBytes | ✅ | ✅ |
randomFill | ✅ | ✅ |
randomFillSync | ✅ | ✅ |
randomInt | ✅ | ✅ |
randomUUID | ✅ | ✅ |
randomUUIDv7 | ✅ | ✅ |
rng | ✅ | ✅ |
scrypt | ✅ | ✅ |
scryptSync | ✅ | ✅ |
secureHeapUsed | ✅ | ✅ |
setEngine | ✅ | ✅ |
setFips | ✅ | ✅ |
sign | ✅ | ✅ |
subtle | ✅ | ✅ |
timingSafeEqual | ✅ | ✅ |
verify | ✅ | ✅ |
webcrypto | ✅ | ✅ |
#Diagnostics
nstdlib running inside Node.js. This isn't an environment it's meant for, so it isn't shown above, but it tells a library problem from an environment one:
coverage: 77/77 of the host's export names answer inside host node. Behaviour verified against the host builtin. Randomness,timingSafeEqualandsubtlerun on the host WebCrypto.createHash/createHmac/hash()/pbkdf2/hkdfare computed in JavaScript for MD5, SHA-1, SHA-2, SHA-3 and the SHAKEs. Ciphers, keys, signing andscryptneed OpenSSL and throw.smoke: Imports in a clean child process.node-suite: 20/145 of Node's own eligible tests pass with ./dist inside host node. A failure there and in the page is the library's, one only in the page is the engine's.wasm-differentials: Hash: pass against the host's own builtin withnstdlib-wasm's blob installed. The published binding refuses without it. Ok nstdlib/node/crypto's digests on 11 algorithm(s) == the host's node:crypto.wasm-differentials: Cipher: pass against the host's own builtin withnstdlib-wasm's blob installed. The published binding refuses without it. Ok nstdlib/node/crypto on CipherBase over 13 cipher(s) == the host's node:crypto.wasm-differentials: Pk: pass against the host's own builtin withnstdlib-wasm's blob installed. The published binding refuses without it. Ok nstdlib/node/crypto on Sign + Verify + KeyObjectHandle + RsaKeyPairGenJob + EcKeyPairGenJob + publicEncrypt + privateDecrypt + DiffieHellman + DiffieHellmanGroup + ECDH + ECDHConvertKey == the host's node:crypto.