Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including strong-cipher with all npm packages installed. Try it out:

var strongCipher = require("strong-cipher")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

strong-cipher v1.0.5

Strong hash and encryption utility using Node's crypto library

Strong-Cipher

Node.js Functional Encryption Helpers

Provides access to strong encryption and hashing, both synchronous and asynchronous, using Node's crypto library.

Encrypt will generate a random iv and salt. These values will be prepended to the encrypted value and used during the decryption process. Identical strings will have different encrypted results but decrypt to the same string.

Hash uses HMAC and a random salt generated for the key. This salt is pre-pended to the resulting hash (similar to bcrypt) and helps reduce common brute force hash attacks.

If the password is incorrect, the methods will throw an error so handle as needed.

Asynchronous methods return a Promise.

Use npm run test or yarn run test to run tests.

Examples:

Encryption

const cipher = require('strong-cipher')

cipher('password').encryptSync('some string')

Produces

WwPeYR7RSIOiH70ubaJ35AVdZb4Q7Vyzb6CWU9sd0tfeMJmQtt3w2fV8b8z9yiv0lP6IJAHaQxBvXCHdS0MYeA==

Hashing

const cipher = require('strong-cipher')

cipher('password').hashSync('some string')

Produces

Ome50nWjXGK0PuqFBYywMkykJoCaKEE4BqztT8rr+CkbxDP+EZMCb6vIKgNaGmjU

Validate Hash

const cipher = require('strong-cipher')

cipher('password').validHashSync('some string', 'Ome50nWjXGK0PuqFBYywMkykJoCaKEE4BqztT8rr+CkbxDP+EZMCb6vIKgNaGmjU')

Produces

true

Random PIN

const cipher = require('strong-cipher')

cipher('password').randomPinSync(6)

Produces

327481

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free