simple-encryptor
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "simple-encryptor", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Simplified encryption/decryption for node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,3 +9,5 @@ # simple-encryptor | ||
npm install simple-encryptor --save | ||
```sh | ||
npm install simple-encryptor --save | ||
``` | ||
@@ -15,40 +17,50 @@ # Usage | ||
// Specify a string key: | ||
// Don't do this though, your keys should most likely be stored in env variables | ||
// and accessed via process.env.MY_SECRET_KEY | ||
var key = 'real secret keys should be long and random'; | ||
```js | ||
// Specify a string key: | ||
// Don't do this though, your keys should most likely be stored in env variables | ||
// and accessed via process.env.MY_SECRET_KEY | ||
var key = 'real secret keys should be long and random'; | ||
// Create an encryptor: | ||
var encryptor = require('simple-encryptor')(key); | ||
// Create an encryptor: | ||
var encryptor = require('simple-encryptor')(key); | ||
``` | ||
To encrypt something: | ||
var encrypted = encryptor.encrypt('testing'); | ||
// Should print gibberish: | ||
console.log('encrypted: %s', encrypted); | ||
```js | ||
var encrypted = encryptor.encrypt('testing'); | ||
// Should print gibberish: | ||
console.log('encrypted: %s', encrypted); | ||
``` | ||
To decrypt it: | ||
var decrypted = encryptor.decrypt(encrypted); | ||
// Should print 'testing' | ||
console.log('decrypted: %s', decrypted); | ||
```js | ||
var decrypted = encryptor.decrypt(encrypted); | ||
// Should print 'testing' | ||
console.log('decrypted: %s', decrypted); | ||
``` | ||
To generate an HMAC: | ||
var myHmac = encryptor.hmac('testing'); | ||
```js | ||
var myHmac = encryptor.hmac('testing'); | ||
``` | ||
Encrypt/decrypt an object (not just a string!): | ||
// nested object: | ||
var obj = { | ||
foo: { | ||
bar: [1, "baz"] | ||
} | ||
}; | ||
var objEnc = encryptor.encrypt(obj); | ||
// Should print gibberish: | ||
console.log('obj encrypted: %s', objEnc); | ||
var objDec = encryptor.decrypt(objEnc); | ||
// Should print: {"foo":{"bar":[1,"baz"]}} | ||
console.log('obj decrypted: %j', objDec); | ||
```js | ||
// nested object: | ||
var obj = { | ||
foo: { | ||
bar: [1, "baz"] | ||
} | ||
}; | ||
var objEnc = encryptor.encrypt(obj); | ||
// Should print gibberish: | ||
console.log('obj encrypted: %s', objEnc); | ||
var objDec = encryptor.decrypt(objEnc); | ||
// Should print: {"foo":{"bar":[1,"baz"]}} | ||
console.log('obj decrypted: %j', objDec); | ||
``` | ||
@@ -80,4 +92,6 @@ # Features | ||
// Don't hard code keys! They should be in environment variables! | ||
var encryptor = require('simple-encryptor')('my secret key'); | ||
```js | ||
// Don't hard code keys! They should be in environment variables! | ||
var encryptor = require('simple-encryptor')('my secret key'); | ||
``` | ||
@@ -93,8 +107,10 @@ ## Options hash - `encryptor(opts)` | ||
// Don't hard code keys! They should be in environment variables! | ||
var encryptor = require('simple-encryptor')({ | ||
key: 'my secret key', | ||
hmac: false, | ||
debug: true | ||
}); | ||
```js | ||
// Don't hard code keys! They should be in environment variables! | ||
var encryptor = require('simple-encryptor')({ | ||
key: 'my secret key', | ||
hmac: false, | ||
debug: true | ||
}); | ||
``` | ||
@@ -107,3 +123,5 @@ # Internals | ||
$ echo "$(< /dev/urandom tr -dc A-Za-z0-9 | head -c 32)" | ||
```sh | ||
$ echo "$(< /dev/urandom tr -dc A-Za-z0-9 | head -c 32)" | ||
``` | ||
@@ -110,0 +128,0 @@ # Dependencies |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128
13008