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 🙏

© 2024 – Pkg Stats / Ryan Hefner

cryptaculous

v0.0.11

Published

A utility with zero dependencies to encrypt and decrypt values ​​by abstracting the native crypto package.

Downloads

22

Readme

A crypt utility with zero dependencies to encrypt and decrypt data ​​by abstracting the native crypto module.

Supported Algorithms

| Algorithm | Secure | |--------------------|--------| | AES_128_CBC | 🟢 Yes | | AES_192_CBC | 🟢 Yes | | AES_256_CBC | 🟢 Yes | | AES_128_CFB | 🟢 Yes | | AES_192_CFB | 🟢 Yes | | AES_256_CFB | 🟢 Yes | | AES_128_CTR | 🟢 Yes | | AES_192_CTR | 🟢 Yes | | AES_256_CTR | 🟢 Yes | | AES_128_ECB | 🔴 No | | AES_192_ECB | 🔴 No | | AES_256_ECB | 🔴 No | | AES_128_OFB | 🟢 Yes | | AES_192_OFB | 🟢 Yes | | AES_256_OFB | 🟢 Yes | | CHACHA20_POLY_1305 | 🟢 Yes | | RSA | 🟢 Yes |

Examples

Try to use secure algorythms but the most important is how you protect the keys.

Usage

Factory method

Using the factory method

import { EncryptionFactory, Algorithm } from 'cryptaculous';

const crypt = EncryptionFactory.createEncryption(Algorithm.AES_256_CBC, {
    key: "1c5b2bc5789a0f9b0c576950aaf049b6",
    iv: "704a59f3d523c765",
});

const cryptedSecret = crypt.encrypt("secret");        // -> EV2YEWJZcpLdBrkqdDij3Q==
const decryptedSecret = crypt.decrypt(cryptedSecret); // -> secret

Strategy pattern

Using a strategies to change the strategy in execution time

import { Encryption, Aes256Cbc } from 'cryptaculous';

const crypt = new Encryption();

if (config.encryptionAlgorith === Algorithm.AES_256_CBC) {
    crypt.setStrategy(new Aes256Cbc({
      key: "1c5b2bc5789a0f9b0c576950aaf049b6",
      iv: "704a59f3d523c765",
    }))
}

const secret = "secret";
const crypted = crypt.encrypt(secret);    // -> EV2YEWJZcpLdBrkqdDij3Q==
const decrypted = crypt.decrypt(crypted); // -> secret

Note: If no strategy set throws MissingStrategyException

Random encryption is a secure way to use different key and initial vector without defining them each time.

It allows you to generate encryption by passing only the value to be encrypted, and it will generate the key and the vector, returning them as a keychain for future use.

The decrypt method receives that keychain and returns the original value.

RandomEncryption

Note: Only compatible with Symmetric algorythms

import { RandomEncryption, Algorithm } from 'cryptaculous';

const cryptedValue = RandomEncryption.encrypt(Algorithm.AES_256_CBC, "secret");

/*
  cryptedValue {
    payload: 'sSnpCXqFnB+Q1VIf4bL0Fw==',
    algorithm: 'aes-256-cbc',
    key: '3668f7a00c5b762c14f2792b0fa866e3',
    iv: '5f5806eca2eceae3'
  }
*/

const decryptedValue = RandomEncryption.decrypt(cryptedValue) // -> secret

RSA

import { Encryption, RsaEncryption } from 'cryptaculous';

const encryption = new Encryption();
const rsaStrategy = new RsaEncryption();

const { privateKey, publicKey } = RsaEncryption.generateKeyPairSync('rsa', {
    modulusLength: 2048,
    publicKeyEncoding: { type: 'spki', format: 'pem' },
    privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
});

encryption.setStrategy(rsaStrategy);
rsaStrategy.setKeys({ privateKey, publicKey });

const secret = 'secret';
const crypted = encryption.encrypt(secret); 

/*
cryped:
G8r816lSY0MVBcxq4EY14SeaoU4oIAK9I2PP8bksLt3KpVzkr7Ncnt4g9517noffn9P1dHbdwxvw9EIMjD4JtuR2okL4TK0BjgMlAoN07SikHmucmcoVF9IdFAK7FcT6LiEveVktSN+Wfu/nOQLH3t032Tk2aaS9vOVGo8j6LFSf5zZcJpgs4/mLh7Z25SUden47CFc2X18I+BUx6ufKfGulq3CLO4oyXGQ+Pw0BNLH5ZRr564kaJcrKx4Dr/ZxxdMVEj8N6K39MonVGebTlNCHbkJdFh0z/bklJXRaGeMke6homSD3yKvb7O45LOlz+fKme2MvCWl+8LLt4SB/cUQ==
*/

const decrypted = encryption.decrypt(crypted);

const decryptedValue = RandomEncryption.decrypt(cryptedValue) // -> secret

// You could use compare method
rsa.compare("secret", crypted) // -> true

Exceptions

| name | |:------------------------------| | UnsupportedAlgorithmException | | MissingStrategyException | | InvalidKeyLengthException | | InvalidIVLengthException | | DecryptionFailedException | | EncryptionFailedException | | MissingPrivateKeyException | | MissingPublicKeyException |