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

crypton

v1.0.8

Published

Node module that provides cryptographic functionalities

Downloads

12

Readme

Crypton 1.x

Node module that provides cryptographic functionalities using crypto for ciphering and bcrypt for encryption.

Installation

In your project root run from command line:

$ npm install -save crypton

Example

Let's start! Include in your node application crypton module:

//require object
var Crypton = require('crypton').Crypton;
//or require factory
var factory = require('crypton');

//create options
var options = {
  crypto: {
    secretKey: 'o!rDE(Qbrq7u4OV',
    algorithm: 'AES-256-CBC',
    inputEncoding: 'utf8',
    outputEncoding: 'base64'
  },
  bcrypt: {
    saltRounds: 5
  }
};

//create an instance
var cryptoManager1 = new Crypton(options);
//or use factory
var cryptoManager2 = factory.create(options);

cryptoManager1.cipher('mytext')
.then(function(res) {
  console.log(res);
});

Documentation

Construction

A Crypton instance can be created using factory or using the new keyword.

var factory = require('crypton');
var cryptonManager1 = factory.create();
//or
var Crypton = require('crypton').Crypton;
var cryptonManager2 = new Crypton();

new Crypton( [options] ) : Object

The crypton module can be initialized with a configuration object.

Arguments

[options] {Object} Optional configuration

Returns

{Object} Get an instance

The configuration object allows you to overrides default values. If you don't specify any configuration, it uses a default object:

{
  crypto: {
    secretKey: 'o!rDE(Qbrq7u4OV',
    algorithm: 'AES-256-CBC',
    inputEncoding: 'utf8', //utf8|base64|hex
    outputEncoding: 'base64' //utf8|base64|hex
  },
  bcrypt: {
    saltRounds: 5 //the cost of processing the data
  }
}

Methods

cipher( text, [options] ) : Promise( string )

Cipher a text with crypto. The operation is reversible. Options param could be the entire crypto configuration or only an attribute:

{
  secretKey: 'o!rDE(Qbrq7u4OV'
}

Arguments

text      {string} Text to cipher
[options] {object} Overrides configuration

Returns

{string} Returns the ciphered text

Throws

{CipherCryptonError}

decipher( text, [options] ) : Promise( string )

Decipher a ciphered text with crypto. Options param could the entire crypto configuration or only an attribute:

{
  secretKey: 'o!rDE(Qbrq7u4OV'
}

Arguments

text      {string} Text to decipher
[options] {object} Overrides configuration

Returns

{string} Returns the deciphered text

Throws

{DecipherCryptonError}

crypt( text, [options] ) : Promise( string )

Crypt a text with bcrypt. The operation is not reversible. Options param could the entire bcrypt configuration or only an attribute:

{
  saltRound: 10
}

Arguments

text      {string} Text to crypt
[options] {object} Overrides configuration

Returns

{string} Returns the crypted text

Throws

{EncryptCryptonError}

compare( text, ciphered, force, [options] ) : Promise( bool )

Check if the clear text matches with the ciphered text. If force is specified it accepts two ciphered strings to compare. Use this method only with ciphered text. Options param could the entire crypto configuration or only an attribute:

{
  secretKey: 'o!rDE(Qbrq7u4OV'
}

Arguments

text      {string}  Text to compare with ciphered
ciphered  {string}  Ciphered text
force     {bool}    Force the compare
[options] {object}  Overrides configuration

Returns

{bool} Returns the result of the match

Throws

{CompareCryptonError}

verify( text, crypted ) : Promise( bool )

Check if the clear text matches with the crypted text. Use this method only with crypted text.

Arguments

text     {string}  Text to compare with crypted
crypted  {string}  Crypted text

Returns

{bool} Returns the result of the match

Throws

{VerifyCryptonError}

md5( text ) : Promise( string )

Get md5 hash of a given string.

Arguments

text  {string} Text to hash

Returns

{string} Returns md5sum in hex format

Throws

{Md5CryptonError}

randomBytes( len ) : Promise( string )

Get random bytes.

Arguments

len  {int} Bytes length

Returns

{string} Returns bytes in hex format

Throws

{RandomBytesCryptonError}

License

The MIT License

Copyright (c) 2017 Michele Andreoli http://thinkingmik.com