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 🙏

© 2025 – Pkg Stats / Ryan Hefner

internal_encryption

v1.0.4

Published

This is an internal encryption library.

Readme

🔐 internal_encryption

A lightweight encryption and hashing library with provider-based key management.
Currently supports HashiCorp Vault, with plans to add streaming support and additional providers in the future.


Document

Google Docs

Installation

npm install internal_encryption

Key format.

alt text

Key version

Key name and path name should be same.

alt text

Environment Variables

You must configure the following environment variables before using the library:

    HASHICORP_VAULT=http://localhost:8200/v1/kv/data
    HASHICORP_TOKEN=root
    import * as dotenv from "dotenv";
    dotenv.config();

    import Encryption from "internal_encryption";

    // Example config (can be fetched from DB, Redis, etc.)
    const config = {
        provider: "hashicorp",
        defaultPolicy: "default"
    };

    const payload = {
        name: "Mike",
        message: "this is a secret message",
    };

    const encryption = new Encryption(config.provider, {
        defaultPolicy: config.defaultPolicy,
    });

    const encryptionAndDecryption = async () => {
        const encryptedPayload = await encryption.encrypt(payload);
        const decryptedPayload = await encryption.decrypt(encryptedPayload);

        console.log(encryptedPayload, decryptedPayload);
    };
    encryptionAndDecryption();

    const hasing = async () => {
        let hashOne = await encryption.hash(payload);
        let hashTwo = await encryption.hash(payload);

        console.log(hashOne, hashTwo);
        console.log("isSame = ", hashOne.hash == hashTwo.hash);
    };
    hasing();

    const hasingWithVersion = async () => {
        let hashOne = await encryption.hash(payload, {
            version: 1,
            type: "password",
        });
        let hashTwo = await encryption.hash(payload, {
            version: 1,
            type: "password",
        });

        console.log(hashOne, hashTwo);
        console.log("isSame = ", hashOne.hash == hashTwo.hash);
    };
    hasingWithVersion();

    // Store the encrypted results as base64 string.
    const base64Encode = () => {
        return new Transform({
            transform(chunk, _enc, cb) {
            cb(null, chunk.toString("base64"));
            },
        });
    };

    const base64Decode = () => {
        return new Transform({
            transform(chunk, _enc, cb) {
            cb(null, Buffer.from(chunk.toString(), "base64"));
            },
        });
    };

    const encryptionAndDecryptionStreams = async () => {
        const inputFile = path.join(__dirname, "longtext.txt");
        const encryptedFile = path.join(__dirname, "encrypted.txt");
        const decryptedFile = path.join(__dirname, "decrypted.txt");

        const encryptedPayload = await encryption.encryptStream(
            fs.createReadStream(inputFile)
        );

        const encryptedWritable = fs.createWriteStream(encryptedFile);
        await pipeline(encryptedPayload.stream, base64Encode(), encryptedWritable);

        const tag = encryptedPayload.getTag();
        if (!tag) throw new Error("Encryption failed: authTag is missing");

        const encryptedReadStream = fs
            .createReadStream(encryptedFile)
            .pipe(base64Decode());

        const decryptedStream = await encryption.decryptStream({
            stream: encryptedReadStream,
            salt: encryptedPayload.salt,
            iv: encryptedPayload.iv,
            tag: tag,
            type: encryptedPayload.type,
            version: encryptedPayload.version,
            provider: "hashicorp",
            algorithm: "aes-256-gcm",
        });

        const decryptedWritable = fs.createWriteStream(decryptedFile);
        await pipeline(decryptedStream, decryptedWritable);

        console.log("✅ Encryption & Decryption completed successfully!");
    };

Features

- 🔑 Provider-based encryption and hashing
- 🏗️ Currently supports HashiCorp Vault
- 📄 Easy integration with .env configs
- 📦 Small payloads optimized (stream support coming soon)

Common Errors

- INVALID_CONFIGURATION: Missing required field 'providerName' in configuration.
- INVALID_CONFIGURATION: Missing required field 'defaultPolicy'.
- INVALID_PAYLOAD: The provided payload is empty, malformed, or not supported. Please ensure a valid string or stream is passed.
- INVALID_PAYLOAD: The provided payload is empty, malformed, or not supported. Some keys are missing. ( Decryption )
- TYPE_OR_VERSION_NOT_FOUND: The requested key type or version is not defined.
- KEY_NOT_FOUND: No matching key found. Either the key is missing, the provided type is invalid, or the requested version does not exist.
- VERSION_NOT_FOUND: The requested key version is missing or does not exist.
- INVALID_ENCRYPTION_DETAILS: Encryption failed due to invalid payload, type, or version.
- INVALID_DECRYPTION_DETAILS: Decryption failed because the payload is invalid, corrupted, or incompatible with the provided key.