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

string-crypto

v3.0.2

Published

Small, simple, and secure no-dependency library to encrypt and decrypt strings using PBKDF2 for key derivation and AES (defaulted to 256-bit / SHA512)

Downloads

5,216

Readme

String Crypto logo depicting a ball of yarn being weaved by a vintage looking key

String Crypto

Tests Try string-crypto on RunKit NPM Downloads

All Contributors

Small, simple, and secure library to encrypt and decrypt strings using PBKDF2 for key derivation and AES (defaulted to 256-bit / SHA512).

This project is open to updates by its users, I ensure that PRs are relevant to the community. In other words, if you find a bug or want a new feature, please help us by becoming one of the contributors ✌️ ! See the contributing section.

Breaking Changes in v3

  • Digest Option Removed: The ability to specify a digest method for key derivation has been removed due to the underlying library (crypto-js) not supporting this functionality directly. We switched to using crypto-js since Node's crypto is commonly breaking due to a missmatch with openssl versions.
  • Key Size Specification: Key size can now be specified in bits as an option when encrypting or decrypting, providing users with the flexibility to define the strength of encryption according to their needs.
  • Default Salt Generation: The default salt is now generated dynamically for each encryption operation if not specified by the user, enhancing security by preventing the use of static salts.

Features

  • Encryption and decryption of strings using PBKDF2 (for key derivation) and AES (Advanced Encryption Standard) in CBC mode.
  • Dynamic generation of a secure random salt for each encryption operation when not specified.
  • Customizable number of iterations for key derivation, enhancing the security against brute force attacks.
  • Key size can be specified in bits, allowing for AES-128, AES-192, and AES-256 encryption strengths.
  • Simplified CLI and library interfaces for straightforward usage in encrypting and decrypting strings.
  • Secure random initialization vector (IV) generation for each encryption operation, ensuring ciphertext uniqueness.

Like this module? ❤

Please consider:

Usage CLI

Encrypting a String

To encrypt a string, use the encrypt command with the required options:

npx string-crypto encrypt --string "Your String Here" --password "YourPassword"

Optional parameters:

  • --salt: Custom salt for encryption. If omitted, a random salt will be used.
  • --iterations: Number of iterations (default is 1000).
  • --keySize: Key size in bits (default is 256).

Decrypting a String

To decrypt a string, use the decrypt command with the required options:

npx string-crypto decrypt --string "EncryptedStringHere" --password "YourPassword"

Optional parameters are the same as for encryption, except --digest is no longer available.

Help

For more information or to see all available options, you can use the -h or --help flag:

npx string-crypto --help

Usage Library

npm i string-crypto
pnpm i string-crypto
yarn add string-crypto
import StringCrypto from 'string-crypto';

const stringToProtect = 'What is the largest (rational) number n such that there are positive integers p, q, r such that 1 - 1/p - 1/q - 1/r = 1/n?';

const password = 'Oh-no,not-again';

const sc = new StringCrypto();

let encryptedString = sc.encryptString(stringToProtect, password);

console.log('Encrypted String:', encryptedString);

console.log('Decrypted String:', sc.decryptString(encryptedString, password));

Options

const options = {
  salt: '2f0ijf2039j23r09j2fg45o9ng98um4o',
  iterations: 1000,
  keySize: 256, // Specify key size in bits
};

const sc = new StringCrypto(options);

Development and build scripts

I chose Rollup to handle the transpiling, compression, and any other transformations needed to get your Typescript code running as quickly and performant as possible.

This repo uses runkit.js to validate code sanity. Why? Because www.npmjs.com uses Runkit to allow potential users to play with your module, live on their browser, which is one of the best ways to convince someone to use your modules in their code. Runkit will look for the runkit.js by default and display that as the initial playground for the user, so by making it the default validation method during development, this encourages proper communication with the users of your code.

Development

yarn dev

Uses concurrently to run Rollup in watch mode (which means it will transpile to dist when you save changes to your code), as well as Nodemon to listen for changes in the dist directory and re-run the runkit.js as you modify your source! This includes running node with the --inspect flag so you can inspect your code using Google Chrome Dev Tools (by opening chrome://inspect in your browser), you're welcome ;)

Build

yarn build

This command will build the dist/index.js, uglified and tree-shaken so it loads/runs faster.

It also generates a source map and a dist/index.d.ts type file for Typescript importing convenience.

Contributing

Yes, thank you! This plugin is community-driven, most of its features are from different authors. Please update the docs and tests and add your name to the package.json file.

Contributors ✨

Thanks goes to these wonderful people (emoji key):