An easy-to-read collection of tiny, focused examples that show how to do common cryptography building blocks in Node.js using the built‑in crypto module:
| Topic | File |
|---|---|
| SHA‑256 hashing + constant time compare | hash.js |
| HMAC signing & verification | hmac.js |
| Symmetric AES‑256‑CBC encryption | symmetric.js |
| Authenticated AES‑256‑GCM encryption | symmetric_gcm.js |
| RSA public key encryption (hybrid building block) | asymmetric.js |
| Hybrid RSA + AES‑GCM key wrapping | hybrid.js |
| ECDH P-256 + AES Key Wrap (RFC3394) | ecdhe_p256_kw.js |
| RSA signatures | signing.js |
| Ed25519 signatures | ed25519_x25519.js |
| X25519 key agreement (ECDH) | ed25519_x25519.js |
| WebCrypto AES-GCM helpers (browser) | webcrypto.js |
| Salted password storage with scrypt | salt.js |
| Argon2 password hashing (modern KDF) | argon2pw.js |
| RSA keypair generation helper | keypair.js |
| Quantum key distribution (BB84 simulation) | quantum/bb84.js |
| HKDF (RFC5869) & PBKDF2 | hkdf_pbkdf2.js |
⚠️ These examples are for learning. For production security: use vetted higher‑level libs, prefer AEAD modes (AES‑256‑GCM / ChaCha20-Poly1305), memory‑hard password hashing (Argon2id), robust key management, and keep dependencies patched.
Starring helps others discover a clean, minimal cryptography reference without extra complexity. More stars = more examples, docs, and security footnotes. If this saved you 5+ minutes of searching, please ⭐ now – it really helps.
npm install cryptography-mini-lab
# or clone and run tests
git clone https://github.com/EdisonTKPcom/Cryptography.git
cd Cryptography
npm install
npm testNode.js 18+ recommended (modern crypto defaults & stable APIs).
You can import individual modules or the aggregate index.js.
const cryptoLab = require('cryptography-mini-lab');
const { hash, hashesEqual } = cryptoLab;
const h1 = hash('hello');
const h2 = hash('hello');
console.log('match?', hashesEqual(h1, h2));
const { generateKey, generateIv, encrypt, decrypt } = cryptoLab;
const key = generateKey();
const iv = generateIv();
const c = encrypt('secret', key, iv);
console.log('plain', decrypt(c, key, iv));Each source file can also be run directly for a live demo:
node hash.js
node symmetric.js
node asymmetric.js
node signing.js
node hmac.js
node salt.jsLightweight Jest tests ensure round‑trip correctness of the primitives.
npm testRun micro benchmarks (approximate):
npm run benchTag a new semver version to trigger the publish workflow:
git tag v1.4.0 && git push origin v1.4.0Ensure NPM_TOKEN secret is configured in the repository settings.
See ROADMAP.md for an extended list. Status highlights:
- Ed25519 / X25519 examples
- HKDF + PBKDF2 utilities
- Argon2 password hashing example
- Quantum (BB84) simulation
- ECDSA example
- Hybrid encryption (RSA/ECDH + AES-GCM)
- Streaming GCM + file encryption helpers
- Safer / vetted AES Key Wrap alternative or guidance
- PQC (Kyber / Dilithium) integration (when stable libs available)
- semantic-release integration
Open an issue to request more examples or vote on priorities.
- Fork
- Create a branch:
feat/add-example-x - Add or update tests
- Submit a PR – small & focused preferred
Security-related clarifications welcome. Please avoid submitting intentionally weak patterns unless accompanied by an educational warning.
Prefer a guided path? See TUTORIAL.md for a step‑by‑step walk‑through from hashing → authenticated encryption → signatures → Argon2 → quantum key distribution simulation.
If this repo helps you teach, prototype, or learn: starring, forking, or sharing is the easiest way to support. For feature funding or security review sponsorship:
- Click the GitHub Sponsor button (see
FUNDING.yml) - Open a discussion with ideas
- (Future) OpenCollective / Patreon
Automated CI runs Jest + ESLint. CodeQL workflow performs static analysis weekly & on PRs.
AES Key Wrap implementation provided is minimal & educational; prefer a vetted library if using in production.
- Node.js Crypto Docs
- OWASP Cryptographic Storage Cheat Sheet
- NIST SP 800-57 & SP 800-63 (key management & digital identity)
- IETF RFC 5869 (HKDF), RFC 8446 (TLS 1.3)
MIT – see LICENSE. Attribution appreciated but not required.
Star now so you can find this again later. 🔖