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

vault-nacl

v1.0.0

Published

A symmetric encrypted vault using nacl elliptic curves

Downloads

59

Readme

vault-nacl

A symmetric encrypted vault using tweetnacl elliptic curves

NPM version

Allows to symmetrically encrypt dedicated values in a configuration file, or the complete file itself, using one password.

Implements xsalsa20-poly1305 secretbox and pbkdf2 with different digests for safe encryption.

Default is sha256 (310000 iterations) which can be changed to 'sha384', 'sha512' (120000 iterations).

Uses VAULT_NACL(...) markers with Base64 encrypted secret inside the vault to identify encrypted values for decryption.

New values attributed with VAULT_NACL(...)VAULT_NACL are used for later encryption.

Choose the CLI or API to fit your usecase.

toc

installation

npm install --save vault-nacl

usage cli

Encrypt single value

$ vault-nacl encrypt
✔ Vault password · ***************
✔ Confirm Vault password · ***************
✔ Secret · *********
VAULT_NACL(AQAQJwAA6mwY4MkxGLKi4T0IZaOeh5Ul7iUv7SRzYK50xQR8iYNOXZQ9+lmSSb8PYkkk5zITgbCC/HbAJJ2B)

Decrypt single value

$ vault-nacl decrypt
✔ Vault password · ***************
✔ Vault · VAULT_NACL(AQAQJwAA6mwY4MkxGLKi4T0IZaOeh5Ul7iUv7SRzYK50xQR8iYNOXZQ9+lmSSb8PYkkk5zITgbCC/HbAJJ2B)
my secret

Encrypt a configuration file

echo {"secret":"VAULT_NACL(my secret hidden value)VAULT_NACL"} > config.json

$ vault-nacl encrypt config.json
✔ Vault password · ***************
✔ Confirm Vault password · ***************

$ cat config.json
{"secret":"VAULT_NACL(AQAQJwAA+XJjGfdtC8jCt7xsWoPBCz2p/qs5MXpzmsqV5jFGCm6xfZgKcADzu3glf1z/5KxKaFFJbtCvX5rAqh/jq3UhRsMHHirldw==)"}

Decrypt a configuration file

$ vault-nacl decrypt config.json
✔ Vault password · ***************
✔ Confirm Vault password · ***************
{"secret":"my secret hidden value"}

See vault-nacl --help for complete list of options.

Or take a look at the man-page.

api

enc-decrypt

asynchronous

EncDec handles VAULT_NACL(...) encoded strings in strings or objects.

const { EncDec } = require('vault-nacl')
const password = '$€creT'
const secret = { mySecret: `VAULT_NACL(a $€Cr3T secret)VAULT_NACL` }

const encdec = new EncDec(password)
const result = await encdec.encrypt(secret)
//>  { mySecret: 'VAULT_NACL(AQAQJwAA+CWBR7...+qAo=)' }

await encdec.decrypt(result)
//> { mySecret: 'a $€Cr3T secret' }

synchronous

EncDecSync handles VAULT_NACL(...) encoded strings in strings or objects synchronously.

NOTE: This function is blocking.

const { EncDecSync } = require('vault-nacl')
const password = '$€creT'
const secret = { mySecret: `VAULT_NACL(a $€Cr3T secret)VAULT_NACL` }

const encdec = new EncDecSync(password)
const result = encdec.encrypt(secret)
//>  { mySecret: 'VAULT_NACL(AQAQJwAA+CWBR7...+qAo=)' }

encdec.decrypt(result)
//> { mySecret: 'a $€Cr3T secret' }

vault

Vault provides the interface to en- and decryption.

asynchronous

const { Vault } = require('vault-nacl')

const password = '$€creT'

async function main() {
  const vault = new Vault(password)

  const ciphertext = await vault.encrypt('my secret message')
  const orginal = await vault.decrypt(ciphertext)
  //> 'my secret message'

  vault.clear() // clear password
}
main()

synchronous

This example uses a different digest and iterations:

const { Vault } = require('vault-nacl')

const password = '$€creT'

const vault = new Vault(password, { digest: 'sha512', iterations: 20000 })
const ciphertext = vault.encryptSync('my secret message')
const orginal = vault.decryptSync(ciphertext)
//> 'my secret message'

vault.clear() // clear password

internals

Format of the base64 encrypted secret:

Version 1

| 1 Byte | 1Byte | 4Bytes | 32Bytes | n-Bytes | | --------- | ------ | ---------- | ------- | ------------ | | version=1 | digest | iterations | salt | boxed secret |

  • digest: digest index. See src/Vault.js DIGESTS 0='sha256', 1='sha384', 2='sha512', 3='ripemd', 4='whirlpool'
  • iterations: Number of iterations. Default 310000
  • salt: Used salt for key derivation

license

MIT licensed