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

cbc-partial-decrypt

v1.0.2

Published

Returns a stream of partial contents of an AES-CBC encrypted resource

Downloads

3

Readme

aes-cbc-partial-decrypt

In CBC mode, the only thing needed to decrypt a specific block, is the ciphertext, key and previous ciphertext (to use as IV).

CBC mode

This library takes advantage of that, and implements partial decryption for AES-CBC with 128, 192 or 256 key length. Although other algorithms should be possible to implement as well.

It will return a stream that can be read, and will emit the resource decrypted from byte start to byte end specified.

How to use

var partialDecryptStream = require('cbc-partial-decrypt')

var opts = {
  mode: 'aes-cbc-256', // which encryption algorithm and mode to use, passed directly to internal decipher
  keyLength: 256, // They keylength to use, to generate the Buffer version if password as a string is used
  password: 'password', // The password to use, either text or Buffer
  iv: 'd', // optional: initial IV with which the file was encrypted. If blank, the default one will be used
  start: 0, // optional: first byte to receive. Default 0
  end: 250, // optional: last byte to receive, included. Default until end of file
  // Function that should have the same signature as fs.createReadStream, and should
  // return a stream that reads the resource to decrypt. opts will have `start` and `end`.
  // They will be different to the ones above, as this function will require the resource needed
  // to also get the IV, and handles the blocksize of AES, so every part can be properly decrypted
  encrypted: function (opts) {
    return fs.createReadStream('path', opts)
  }
}

partialDecryptStream(opts).pipe(process.stdout) // prints partial resource

Notes

Specify end byte

This library uses setAutoPadding(false) on the internal crypto.createDecipheriv(), so it is recommended to know the original size of the resource, and use it as end when reading until the end of the file, as the default padding will be emitted as data as well, unless cut out.

Non-stream mode

The library only offers to return back a stream, but the method should work aswell done synchronously with a part of the resource. Happy to accept PR with this functionality.

Other algorithms

As CBC is the block mode, but not the algoritmh itself, it should also be possible to implement this method with different cryptographic algorithms. Happy to accept PR with this functionality.