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