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

node-aescrypt

v1.0.8

Published

A node implementation of the AES Crypt <https://www.aescrypt.com/> file encryption format.

Downloads

16

Readme

node-aescrypt

Build Status Codecov GitHub Stars

A node implementation of the AES Crypt https://www.aescrypt.com/ file encryption format.

How to use this package

This package exposes two different interfaces. If you are just interested in encrypting secrets on your own workstation, you can use the CLI version. If you want to use this in an node application, you can import the node library.

CLI

This simplest way to get started encrypting files is to use NPX to use the executable without necessarily "installing" it. To encrypt a local file you can simply execute:

$ npx node-aescrypt -e -p SUPER_SECURE_PASSWORD README.md

In this case, I'm encrypting the file README.md. After this command executes, you will see a new file in your current directory called README.me.aes. To decrypt this file you can use:

$ npx node-aescrypt -d -p SUPER_SECURE_PASSWORD README.md.aes

This will recreate the README.md file.

For a little more complicated of an example, you can pipe in data from the command line, so you could archive, compress, and then encrypt a directory like this:

$ tar -czf - -C src/ . | npx node-aescrypt -e -p SUPER_SECURE_PASSWORD -o my-src.tgz.aes

And then if you wanted to reconstitue that directory, you can move the my-src.tgz.aes file where ever you need it and execute:

$ npx node-aescrypt -d -p SUPER_SECURE_PASSWORD -o - my-src.tgz.aes | tar -pxzf -

Library

The primary reason I built this package was actually to integrate it into build systems. I planned to use the simple AES Crypt https://www.aescrypt.com/ app to encrypt secrets, and then this library, which is binarily compatibile with it, to decrypt on the fly using ENV variables to store my password.

To use the library version you should import the Decrypt or Encrypt classes from the module. These classes implement the node stream.Transform interface, so that they can be piped through by any Readable and/or Writable stream. So for example if you wanted to encrypt a file you could do this:

import { createReadStream, createWriteStream } from 'fs';
import { Encrypt } from 'node-aescrypt';

const from = createReadStream('somefile.txt');
const to = createWriteStream('somefile.txt.aes');
const through = new Encrypt('SUPER_SECURE_PASSWORD');

from
  .pipe(through)
  .pipe(to)
  .on('error', () => console.error('Oh no!  Something went wrong.'))
  .on('finish', () => console.log('All done.'));

For decrypting, it is the exact same process, but make sure the from stream is your encrypted file, the to stream is to a new file to put the decrypted data into, and you use the Decrypt class instead of the Encrypt class.

This makes the library very flexible because you can chain these streams in many different ways. For example, you could pipe the data through a Zlip https://nodejs.org/api/zlib.html transformer before you pipe it through the Encrypt object. You could even serve it from a server by piping it into an http.ServerResponse https://nodejs.org/api/http.html#http_class_http_serverresponse object.