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

altruist-encrypt

v1.0.4

Published

RSA and Diffie-Hellman encryption library for Node.js

Readme

altruist-encrypt

This is a simple npm package for encryption and decryption of data. It can be used for encryption of UTF-8 data that needs to be decrypted at a later time. This package combines both diffiehellman and rsa encryption approach and you can choose any of them depending on your preference and requirements.

⚠️ Note: This package is only compatible with Node.js environments. It does not support frontend frameworks like React or Angular.

Below is a short feature:

  • RSA Encryption with signatures (for secure, verifiable messaging)
  • Diffie-Hellman key exchange (for secure shared secrets over public networks)

Built entirely on the Node.js crypto module — no file storage for keys (in-memory only).

Features

  • Generate RSA key pairs (in-memory)
  • Sign and verify messages with RSA
  • Encrypt and decrypt messages with RSA
  • Perform secure Diffie-Hellman key exchange
  • Encrypt and decrypt messages with shared Diffie-Hellman secrets
  • Class-based, simple API
  • No external dependencies
  • Typescript Support

Installation

npm install altruist-encrypt

Or

yarn add altruist-encrypt

Quick Start

RSA Encryption

import { RSAEncryption } from "altruist-encrypt"

// Initialize
const rsa = new RSAEncryption()

// Generate key pair (public and private)
rsa.generateKeys()

const payload = "This is a sample test" or JSON.stringify({ name: "package" })

// Encrypt and sign (signature happens under the hood)
const encrypted: any = rsa.encrypt(JSON.stringify(payload))
console.log(encrypted) 

// Decrypt and verify (verification happens under the hood)
const decrypted: any = rsa.decrypt(encrypted.data, encrypted.signature)
console.log(decrypted)  

Diffie-Hellman

import { DiffieHellman } from "altruist-encrypt"

// Initialize
const encryption = new DiffieHellman()

// Generate initiator (sender) keys
const initiatorKeys = await encryption.getInitiatorKeys()

const payload = "This is a sample test" or JSON.stringify({ name: "package" })

// Encrypt
const encrypted = await encryption.encrypt(initiatorKeys.publicKey, payload)
console.log(encrypted) 

// Decrypt
const decrypted: any = await encryption.decrypt(encrypted.pubKey, { payload: encrypted.payload, salt: encrypted.salt })
console.log(decrypted)

API Reference

RSA Encryption

new RSAEncryption() Creates a new RSA handler instance

.generateKeys() Generates an RSA public-private key pair in memory

  • Return void

.encrypt() Encrypts and signs a message using RSA.

  • Parameters:
    • payload(string): Message to encrypt
  • Returns:
    • { data: string; signature: string }
      • data: Base64 encrypted payload
      • signature: Base64 signature of original message

.decrypt(encryptedData: string, signature: string) Decrypts and verifies a message.

  • Parameters:
    • encryptedData(string): Base64-encoded encrypted message
    • signature(string): Base64-encoded signature.
  • Returns:
    • On success: Decrypted string
    • On failure: { error: string }

Diffie-Hellman

new DiffieHellmanEncryption() Creates a new Diffie-Hellman encryption instance

.getInitiatorKeys()

  • Returns:
    • { publicKey: string, secretKey: string }
      • publicKey: Hexadecimal-encoded shared public key
      • secretKey: Hexadecimal-encoded shared secret key (should be ignored)

.encrypt(payload: string) Encrypts a message using the shared secret key (e.g., AES derived from the secret)

  • Parameters:
    • payload(string): Plaintext to encrypt
  • Returns: { payload: string, salt: string, pubKey: string } | { error: string }
    • On success:
      • payload(string): Hexadecimal encrypted text
      • salt(string): Random string used for salting
      • pubKey: Base64-encoded sender's public key. Needed to get the secret key from memory
    • On failure:
      • error: String returned if public key cannot be found in memory

.decrypt(publicKey, { payload:string, salt: string }) Decrypts a ciphertext using the shared secret key

  • Parameters:
    • publicKey(string): Base64-encoded shared public key returned from encryption response
    • payload(string): Hexadecimal encrypted text returned from encryption response
    • salt: Random string returned from encryption response
  • Returns: string | { error: string }
    • On success: Decrypted string
    • On failure: { error: string }

Security Notes

  • RSA:
    • Ensures confidentiality via encryption
    • Ensures authenticity and integrity via signature verification
  • Diffie-Hellman:
    • Enables secure key exchange even over insecure networks
    • Does not provide authentication — you should combine with signatures if needed

Note

  • This package is designed for ephemeral communication — no keys are saved to files
  • RSA operations are synchronous, suitable for most short-lived, lightweight encryption tasks

Licesne

MIT License