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

rsa-stream

v1.0.3

Published

encrypt/decrypt rsa with streams

Downloads

49

Readme

rsa-stream

encrypt/decrypt rsa with streams

This module is a bit silly unless you are using it as a wrapper because you shouldn't encrypt too many bytes with asymmetric crypto. Instead, encrypt a key for a symmetric cipher in a short header and then switch to symmetric crypto for the payload.

You should probably be using hybrid-rsa-stream instead.

example

encrypt

var rsa = require('rsa-stream');
var fs = require('fs');
var pubkey = fs.readFileSync(process.argv[2], 'utf8');

var enc = rsa.encrypt(pubkey, { encoding: 'base64' });
process.stdin.pipe(enc).pipe(process.stdout);

output:

$ echo beep boop | node enc.js ~/.ssh/id_rsa.pub
t1Lytqy7CoONohuzIDxoGpErAK4vN9xKWWO/IK4yH/2PvAOIldSAdNg/HhiAWg5PAPwCTSIfINYlpNSQgkw3kK/GtaeEIpAdRnlHh6wNzBcbT7L7R+EZthWzPKpPE9IO0tPM5kBpN8SDr16Z6PC0OxK5ArJAqmbv8hiWzjS384dMYcyYrK6Z0cUawkC2oeZhBf5z6ev1OLTesPF71evJSTIFD3XlbksziAgYIS4CAG+Gwx0avmHwJHnHuvAr/wY3FcVYc4788tmS1YVmRAPrqg/0UoGglnLaSR1DdOJNgw5y/oErlBxXtMV6jEjWLi8XK2hZiKk/ecA921Fx+483zw==

decrypt

var rsa = require('rsa-stream');
var fs = require('fs');
var privkey = fs.readFileSync(process.argv[2], 'utf8');

var dec = rsa.decrypt(privkey, { encoding: 'base64' });
process.stdin.pipe(dec).pipe(process.stdout);

output:

$ echo beep boop | node enc.js ~/.ssh/id_rsa.pub | node dec.js ~/.ssh/id_rsa
Enter PEM pass phrase:
beep boop

methods

var rsa = require('rsa-stream')

var enc = rsa.encrypt(publicKey, opts)

Return an encryption stream enc that will encrypt the data written to it with the given publicKey and output the encrypted stream with opts.encoding ('binary' buffers by default).

publicKey should be a string or buffer with PEM key data or the openssh-style public keys typically found in ~/.ssh that begin with /^ssh-rsa\b/

If more than opts.limit bytes are written, an error is thrown. The default number of bytes is 100, which you should only raise to maximally n/8-11 for an n-bit RSA key.

var dec = rsa.decrypt(privateKey, opts)

Return a decryption stream dec that will decrypt the data written to it in opts.encoding format with the given privateKey.

privateKey should be a string or buffer with PEM or openssh-style /^ssh-rsa\b/ data.

install

To get the library, with npm do:

npm install rsa-stream

license

MIT