jsonmaur / node-crypto-extra

Convenience methods for node crypto
MIT License
14 stars 1 forks source link

Crypto-Extra for Node.js

Build Status Coverage Status

Adds convenience methods to the native Node.js crypto module. It is a drop in replacement, and extends the original module functionality.

Why?

The native crypto module can be a pain to work with, and requires a lot of boilerplate to do things such as randomizing and encryption. This abstracts all of that.

Getting Started

$ npm install crypto-extra --save

To use in your project, simply require into your project as you would the crypto module.

const crypto = require("crypto-extra")

crypto.randomString()
//= L0e84MUt0n

crypto.hash("hello")
//= 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

API

.encrypt (value, secretKey)

Encrypts a value with a secret key using AES-256-CTR.

.decrypt (value, secretKey)

Decrypts a value using AES-256-CTR.

.hash (value, options)

Hashes a string with the provided algorithm.

.randomKey (length)

Generates a random 256-bit key that can be used as an encryption key.

.randomString (length, charset)

Returns a random string of a defined length.

.randomNumber (options)

Returns a random string within a defined range.

License

MIT © Jason Maurer