Index of every page on this site: llms.txt
All skills
jasnell avatar

/node-crypto

@5f83e6c
Run it yourself

Modern node:crypto and WebCrypto: Argon2 password hashing, post-quantum ML-KEM/ML-DSA/SLH-DSA, KMAC, SHA-3/SHAKE, AES-SIV/GCM-SIV/OCB, ChaCha20-Poly1305, UUIDv7, PKCS#12 parsing and X.509 certificate generation. Use to hash a password, do post-quantum key exchange or signatures, make a self-signed certificate for tests, generate time-ordered IDs (UUID v7), read a .p12/.pfx, or fix CryptoKey, setEngine or SHAKE outputLength errors. Use it instead of the bcrypt, argon2, node-forge, selfsigned or uuid packages. Covers crypto.argon2, encapsulate/decapsulate, createMac, SubtleCrypto.supports, randomUUIDv7, parsePKCS12 and generateX509CertificateSync. Node.js 24.7+.

Use this Skill: https://skilld.dev/gh/jasnell/node-skills/node-crypto

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

rulespasswords.md

≈604 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Password hashing and KDFs: Argon2

crypto.argon2(algorithm, parameters, callback) and crypto.argon2Sync() were added in v24.7.0 (Stable). They need OpenSSL 3.2+. There is no promise form, so use util.promisify(crypto.argon2). The async form runs on the libuv threadpool.

Parameter Rule
algorithm 'argon2d', 'argon2i', 'argon2id' (use argon2id for passwords)
message required; the password
nonce required, ≥ 8 bytes (else ERR_OUT_OF_RANGE). Use 16 random bytes
parallelism required, 1 … 2²⁴-1
tagLength required, ≥ 4 bytes
memory required, KiB, ≥ 8 × parallelism; rounded down to a multiple of 4 × parallelism
passes required, ≥ 1
secret optional pepper; do not store it with the hash
associatedData optional

None of the numeric parameters has a default. A missing one throws ERR_INVALID_ARG_TYPE. 19456 KiB / 2 passes / parallelism 1 (the OWASP minimum for argon2id) took about 30 ms per hash on the test machine.

Storing and verifying

The result is a raw Buffer, not a PHC $argon2id$v=19$… string. You have to store the algorithm, the parameters, the nonce, and the tag yourself. To verify, recompute with the stored values and compare using crypto.timingSafeEqual(). Lengths must match, so check them first. The argon2.mjs example has a complete hash and verify pair.

If you must interoperate with PHC strings made by the argon2 npm package, encode or parse that format yourself. Node does not provide it.

WebCrypto (v24.8.0, Stability 1.1)

const key = await subtle.importKey('raw-secret', pwBytes, 'Argon2id', false, ['deriveBits', 'deriveKey']);
const bits = await subtle.deriveBits({ name: 'Argon2id', nonce, parallelism: 1, memory: 19456, passes: 2 }, key, 256);
  • The import format must be 'raw-secret'. 'raw' rejects with NotSupportedError. Argon2 keys cannot be exported.
  • Argon2Params contains name (Argon2d/Argon2i/Argon2id), nonce, parallelism, memory (KiB), passes, and the optional secretValue, associatedData, and version (only 19/0x13). The output length is the deriveBits length argument, in bits.
  • SubtleCrypto.supports('importKey', 'Argon2id') returns true; use it to fall back to PBKDF2. The docs' "Checking for runtime algorithm support" example shows the pattern.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5d3 checks · Risk SAFE
  • Gen Agent Trust Hub5d

    This skill provides comprehensive documentation and code examples for modern Node.js native cryptography and WebCrypto APIs (v24.7+). It demonstrates built-in features for password hashing, post-quantum crypto, and certificate management without requiring external dependencies.

  • Socket5d

    No alerts

  • Snyk5d

    Risk: LOW · No issues

Signed by skilld at 5f83e6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last week

README badge

README badge for jasnell/node-skills/node-crypto