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

@mgraphic/cipher-token

v1.1.0

Published

Package to encrypt and decrypt data into a storable string with multiple options to generate a key

Downloads

223

Readme

Link to the full API Documentation

A package tool to encrypt and decrypt secrets into storable string values without requiring a vault to store them. Tokens can ciphered and deciphered by a single key that can be generated by a string, buffer, file, or auto-generated (to be stored privately), or even a combination of these.

npm install @mgraphic/cipher-token

CLI Tool

npx @mgraphic/cipher-token

Results In...

CLI Example

You can either use the prompt interaction to create a token, decipher a token, or generate a random string to be used for a key.

tokenize

npx @mgraphic/cipher-token tokenize --key=<secret key> [flags...] <plainText>

Arguments |ARGUMENT|DESCRIPTION|TYPE|REQUIRED| |-|-|-|-| |plainText|Plain text to tokenize|string|yes|

Options |FLAG|ALIAS|DESCRIPTION|TYPE|DEFAULT|REQUIRED| |-|-|-|-|-|-| |--cipher-algorithm|-a|Cipher Algorithm|string|aes-256-gcm|false| |--encryption-encoding|-e|Encryption Encoding|string|hex|false| |--hash-algorithm|-y|Hash Algorithm|string|sha256|false| |--key||Secret Key|string||true| |--key-length|-k|Key Length|number|32|false| |--salt-byte-size|-b|Salt Byte Size|number|8|false| |--salt-encoding|-s|Salt Encoding|string|hex|false| |--tag-encoding|-t|Tag Encoding|string|hex|false| |--text-encoding|-x|Text Encoding|string|utf8|false| |--token-encoding|-z|Token Encoding|string|base64|false|

untokenize

npx @mgraphic/cipher-token tokenize --key=<secret key> [flags...] <token>

Arguments |ARGUMENT|DESCRIPTION|TYPE|REQUIRED| |-|-|-|-| |token|Token string to decipher|string|yes|

Options |FLAG|ALIAS|DESCRIPTION|TYPE|DEFAULT|REQUIRED| |-|-|-|-|-|-| |--cipher-algorithm|-a|Cipher Algorithm|string|aes-256-gcm|false| |--encryption-encoding|-e|Encryption Encoding|string|hex|false| |--hash-algorithm|-y|Hash Algorithm|string|sha256|false| |--key||Secret Key|string||true| |--key-length|-k|Key Length|number|32|false| |--salt-byte-size|-b|Salt Byte Size|number|8|false| |--salt-encoding|-s|Salt Encoding|string|hex|false| |--tag-encoding|-t|Tag Encoding|string|hex|false| |--text-encoding|-x|Text Encoding|string|utf8|false| |--token-encoding|-z|Token Encoding|string|base64|false|

generate

npx @mgraphic/cipher-token generate [flags...]

Options |FLAG|ALIAS|DESCRIPTION|TYPE|DEFAULT|REQUIRED| |-|-|-|-|-|-| |--byte-size|-b|Byte Size|number|32|false|

Code Examples

Key From String

const { getCipherToken, getDecipherToken } = require('@mgraphic/cipher-token');

//   Encrypt:
const cipherToken = getCipherToken();
cipherToken.keyFromString('secret_string_key');
const token = cipherToken.tokenize('Secret Text encrypted by a string key');
console.log('Token:', token);

// Decrypt:
const decipherToken = getDecipherToken();
decipherToken.keyFromString('secret_string_key');
const decrypted = decipherToken.untokenize(token);
console.log('Decrypted:', decrypted);

Key From File

const { getCipherToken, getDecipherToken } = require('@mgraphic/cipher-token');

//   Encrypt:
const cipherToken = getCipherToken();
await cipherToken.keyFromFile('package.json');
const token = cipherToken.tokenize('Secret Text encrypted by a file key');
console.log('Token', ': ', token);

//   Decrypt:
const decipherToken = getDecipherToken();
await decipherToken.keyFromFile('package.json');
const decrypted = decipherToken.untokenize(token);
console.log('Decrypted', ': ', decrypted);

Key From Buffer

const { getCipherToken, getDecipherToken } = require('@mgraphic/cipher-token');

//   Encrypt:
const cipherToken = getCipherToken();
cipherToken.keyFromBuffer(Buffer.from('buffer_key'));
const token = cipherToken.tokenize('Secret Text encrypted by a buffer key');
console.log('Token', ': ', token);

//   Decrypt:
const decipherToken = getDecipherToken();
decipherToken.keyFromBuffer(Buffer.from('buffer_key'));
const decrypted = decipherToken.untokenize(token);
console.log('Decrypted', ': ', decrypted);

Key From Buffer, File, and String

const { getCipherToken, getDecipherToken } = require('@mgraphic/cipher-token');

//   Encrypt:
const cipherToken = getCipherToken();
await cipherToken.keyFrom({
  buffer: Buffer.from('buffer_key'),
  text: 'secreat-key-string',
  file: 'package.json',
});
const token = cipherToken.tokenize('Secret Text encrypted by a combo key');
console.log('Token', ': ', token);

//   Decrypt:
const decipherToken = getDecipherToken();
await decipherToken.keyFrom({
  buffer: Buffer.from('buffer_key'),
  text: 'secreat-key-string',
  file: 'package.json',
});
const decrypted = decipherToken.untokenize(token);
console.log('Decrypted', ': ', decrypted);

Key From Random Generated String

const {
  getCipherToken,
  getDecipherToken,
  generateRandomString,
} = require('@mgraphic/cipher-token');

//   Encrypt:
const key = generateRandomString();
const cipherToken = getCipherToken();
cipherToken.keyFromString(key);
const token = cipherToken.tokenize(
  'Secret Text encrypted by a random bytes key'
);
console.log('Token', ': ', token);

//   Decrypt:
const decipherToken = getDecipherToken();
decipherToken.keyFromString(key);
const decrypted = decipherToken.untokenize(token);
console.log('Decrypted', ': ', decrypted);

Author

Keith Marshall [email protected]

License

Copyright © 2024 Keith Marshall [email protected]. This project is MIT licensed.