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

pull-crypto

v1.2.1

Published

crypto via pull-streams

Downloads

14

Readme

pull-crypto

pull-stream wrapper for node's crypto module.

hash

a Sink stream that will callback the hash of a stream (i.e. a file)

var pc = require('pull-crypto')
var pull = require('pull-stream')

pull(
  pull.values(['a', 'b', 'c']),
  pc.hash(function (err, sum) {
    if(err) throw err
    console.log(sum)
  })
)

which will output: a9993e364706816aba3e25717850c26c9cd0d89d

encrypt

a Through stream that takes an options object and returns encrypted data in callback (if callback is supplied) or stream so it can be piped to a consumer.

Below has no callback and returns a stream so you pipe to another stream.

var pc = require('pull-crypto')
var pull = require('pull-stream')

var pass = 'secret'
var alg = 'aes-256-cbc'
var encryptOpts : {
  inputEncoding : 'ascii',
  encoding : 'base64'
}

encryptOpts.password = pass
encryptOpts.algorithm = alg
   
pull(
  pull.values(['a', 'b', 'c']),
  pc.encrypt(encryptOpts),
  pull.log()
)

Note : options object is intentionally verbose in above example to show all properties. The only thing you are required to pass in is the password property. This will ensure your data is not encrypted with any default password. If no password is supplied it will throw!

####Options Object defaults :

  • algorithm : aes-256-cbc
  • inputEncoding : buffer
  • encoding : buffer

decrypt

this is the same as encrypt. It can either be piped down stream or take a callback. Below we take encrypted hex data and pipe it to decrypt and then print out the decrypted data to the console, which yields abc.

var pc = require('pull-crypto')
var pull = require('pull-stream')
var pass = 'secret'

pull(
  pull.values(['9f6199ceee0c2a6f36137fa80eeb2a59']),
  pc.decrypt({
    password : pass,
    inputEncoding : 'hex',
    encoding : 'ascii'
  }),
  pull.log()
)

You can also pass a callback to decrypt.

Below is same example as above with Callback supplied. It also has a slimmed down options object.

var pc = require('pull-crypto')
var pull = require('pull-stream')
var pass = 'secret'
   
pull(
  pull.values(['2ad16d51e86e596f274c00c1674563eb', 'b4d45754b6c12f8f780b8245cefa3b60', 'eba7bdc73915a45cbd7e45b0b2dd2d29']),
  pc.decrypt({
    password : pass,
    inputEncoding : 'hex',
    encoding : 'ascii'
  }, function(err, encrypted) {
    if (err) throw err
    console.log(encrypted.join(''))
  })
)

Note that when using the callback style as above this function will not stream! It will buffer all data until upstream calls cb(true) indicating there is no more data and then it will call your callback with all of the transformed data. The returned data will be in the form of an array. Since the data has been encrypted chunk by chunk you will have to decrypt it chunk by chunk. So the callback style is better suited for decryption. When you don't need to stream and you want all the data back at the same time. All you have to do is call join('') on the returned data to concatinate the decrypted result as shown above (call join() on string data, of course...buffers need to be handled differently).

algorithms

You can choose any algorithm that is available through node's crypto.getCiphers() method. Check out the tests folder, you'll find the most common algorithms tested.

encoding

If you encrypt data as a string please remember you must set opts.inputEncoding in the decrypt options to the same value that the data was originally encrypted or you will not be able to decrypt the data.

See node's crypto module for more details on encoding.

License

MIT