npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

hybrid-crypto-express

v1.0.0

Published

Lightweight hybrid (RSA + AES-GCM) encryption for Node.js and Express microservices

Readme

hybrid-crypto-express

Lightweight hybrid encryption for Node.js and Express: RSA-OAEP for key exchange and AES-256-GCM for payloads. Zero dependencies, uses only Node.js crypto. Suited for microservices and APIs that need optional end-to-end encryption.

Security

  • RSA-OAEP (2048-bit, SHA-256) for encrypting the ephemeral AES key
  • AES-256-GCM (12-byte IV, 16-byte auth tag) for request/response bodies
  • Session keys stored server-side with configurable TTL; no key reuse across sessions
  • Constant-time safe where applicable via Node crypto

Install

npm install hybrid-crypto-express

Server (Express)

const express = require('express');
const {
  HybridCrypto,
  decryptRequest,
  encryptResponse,
  registerCryptoRoutes
} = require('hybrid-crypto-express');

const app = express();
const hybridCrypto = new HybridCrypto({
  sessionExpiryMs: 5 * 60 * 1000  // 5 min
});

// 1) Decrypt encrypted requests (must run before body parser for encrypted paths)
app.use(decryptRequest(hybridCrypto, {
  skipPaths: ['/health', '/', '/api/crypto/public-key', '/api/crypto/handshake']
}));

app.use(express.urlencoded({ extended: true, limit: '10mb' }));
app.use(express.json({ limit: '10mb' }));

// 2) Crypto endpoints + optional test route
registerCryptoRoutes(app, hybridCrypto, { testRoute: true });

// 3) Encrypt responses when client sends X-Encrypted: true
app.use(encryptResponse(hybridCrypto));

app.get('/health', (req, res) => {
  res.json({ status: 'ok', encryption: true });
});

app.post('/api/secure-action', (req, res) => {
  // req.body is decrypted when request was encrypted
  res.json({ received: req.body });
});

app.listen(3000);

Client (Node or microservice)

const { HybridCryptoClient } = require('hybrid-crypto-express');

const client = new HybridCryptoClient('my-service-id');

async function run() {
  await client.handshake('http://localhost:3000');

  const payload = { userId: 1, action: 'submit' };
  const encrypted = client.encryptPayload(payload);

  const res = await fetch('http://localhost:3000/api/secure-action', {
    method: 'POST',
    headers: client.getEncryptedRequestHeaders(),
    body: JSON.stringify(encrypted)
  });
  const body = await res.json();

  if (body.encrypted) {
    const decrypted = client.decryptPayload(body);
    console.log(decrypted);
  } else {
    console.log(body);
  }
}
run();

API

Server

  • HybridCrypto(options?)

    • sessionExpiryMs – session TTL (default 5 min)
    • rsaModulusLength – default 2048
  • decryptRequest(hybridCrypto, options?)

    • Decrypts body when X-Encrypted: true and X-Client-ID are set.
    • options.skipPaths – paths that skip decryption (default includes /api/crypto/public-key, /api/crypto/handshake).
  • encryptResponse(hybridCrypto)

    • Wraps res.json to encrypt when same headers are present.
  • registerCryptoRoutes(app, hybridCrypto, options?)

    • Adds GET /api/crypto/public-key and POST /api/crypto/handshake.
    • options.pathPrefix – default '/api/crypto'.
    • options.testRoute – add POST /api/crypto/test.

Client

  • HybridCryptoClient(clientId?)

    • handshake(baseUrl, fetchOptions?) – fetch public key, send encrypted AES key, establish session.
    • encryptPayload(data) – returns { ciphertext, iv, authTag }.
    • decryptPayload(encrypted) – expects { ciphertext, iv, authTag }.
    • getEncryptedRequestHeaders()X-Client-ID, X-Encrypted: true, Content-Type.
  • getPublicKey(baseUrl, fetchOptions?) – one-off fetch of server public key.

Subpath imports

const { HybridCrypto } = require('hybrid-crypto-express/server');
const { HybridCryptoClient } = require('hybrid-crypto-express/client');
const { decryptRequest, encryptResponse, registerCryptoRoutes } = require('hybrid-crypto-express/middleware');

CORS

Allow these headers so clients can use encryption:

  • X-Client-ID, X-Encrypted, X-Encryption-Type
  • Expose: X-Encrypted, X-Encryption-Algorithm, X-Session-Expiry

License

MIT