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

create-cipher

v3.1.0

Published

node ciphers with better defaults

Downloads

6

Readme

create-cipher Build Status

Whats wrong with crypto.createCipher?

The issues with the default node crypto.createCipher is that it uses a weak and deterministic method of creating a cipher key and initialization vector from your supplied password. There isn't anything wrong with crypto.createCipheriv and if you used crypto.randomByte to create your password you'd also be fine. Node core team members are aware and there should be a better docs soon.

cryto.createCipher generates the key and iv from your password without a salt and using an outdated OpenSSL function, it also only uses only one iteration and md5. The worst problem and the one hardest to solve is the lack of salt, from the OpenSSL docs:

Without the -salt option it is possible to perform efficient dictionary attacks on the password and to attack stream cipher encrypted data. The reason for this is that without the salt the same password always generates the same encryption key.

This is the hardest to solve for node because it has no mechanism to communicate the salt along with the message without destroying backwards compatibility. The other issues of using a non cryptographically secure hash function (md5) and iteration count of 1 make it more feasible to quickly generate keys and ivs dynamically to test a cipher text with. For details of how feasible it is to do an attack like this see this Ars Technica article about cracking password hashes.

What this does

Instead of a single round of md5 with no salt, keys are derived with pbkdf2, a 16 byte random salt, and 1000 iterations (with iterations and salt length configurable). The salt (along with info on the salt length and iteration count) is sent in a header before the encrypted text so all that is needed to know to decrypt the text is the algorithm and password.

API

Similar to crypto.createCipher but

  • just a regular stream
  • two additional (optional) arguments, iterations and saltLen.
var createCipher = require('create-cipher');

createCipher.Cipher(algorithm, password, iterations=1000, saltLen=16);
createCipher.Decipher(algorithm, password);
// no need to pass in iterations or saltLen

Versions

  • 1.0.0: first published
  • 2.0.0: switched the hash at the end of the message to an hmac
  • 2.1.0: changes the default salt length from 512 bytes to 16 bytes
  • 3.0.0 removed the hmac, was done poorly and off focus.