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

@mmeyer2k/aes256gcm

v0.0.0

Published

Wrappers for AES256 GCM authenticated encryption functions. GCM is widely considered to be the most optimal choice for projects needing symmetric encryption.

Downloads

68

Readme

node-aes256gcm

Wrappers for AES256 GCM authenticated encryption functions. GCM is widely considered to be the most optimal choice for projects needing symmetric encryption.

Install

yarn add aes256gcm

Usage

A trivial example of usage is shown below. The resulting encrypted variable will be a buffer containing the encrypted message, IV and auth tag.

const gcm = require('aes256gcm')

const key = "A".repeat(32) // please see "Keys" section

const encrypted = gcm.encrypt('my secret message', key)

Encoding

Buffers are always returned by the encrypt/decrypt functions. If special encoding is needed, use the toString() method.

const encrypted = gcm.encrypt('my secret message', key).toString('base64')

Input data can either be provided as a string or as a buffer. By default, strings will be treated as UTF-8.

const decrypted = gcm.decrypt(Buffer.from(encrypted, 'base64'), key)

Padding

GCM does not pad input data by default. This can leak information about the size of plaintexts. To pad input to block length, use the padded helper object:

const encrypted = gcm.padded.encrypt('my secret message', key)

const decrypted = gcm.padded.decrypt(encrypted, key)

Keys

Keys are required to be exactly 32 bytes. The strength of this key determines the security of your data. No key hardening is performed within this library. Anything other than a completely random password will leave encrypted data in a vulnerable state.

Generate a new base64 encoded key the javascript way:

const gcm = require('aes256gcm')

const crypto = require('crypto')

let key = crypto.randomBytes(32).toString('base64');

console.log(key)

Use the encoded key:

const key = Buffer.from(key, 'base64')

const encrypted = gcm.encrypt('my secret message', key)