node-cipher
Advanced tools
Comparing version 5.0.1 to 6.0.0
@@ -21,2 +21,3 @@ /** | ||
* @const {Array} ALL_CIPHERS | ||
* @see {@link https://nodejs.org/api/crypto.html#crypto_crypto_getciphers} | ||
*/ | ||
@@ -26,2 +27,8 @@ const ALL_CIPHERS = crypto.getCiphers(); | ||
/** | ||
* @const {Array} ALL_HASHES | ||
* @see {@link https://nodejs.org/api/crypto.html#crypto_crypto_gethashes} | ||
*/ | ||
const ALL_HASHES = crypto.getHashes(); | ||
/** | ||
* @const {string} DEFAULT_SALT | ||
@@ -294,2 +301,10 @@ */ | ||
// Verify that the chosen digest is valid. | ||
if (!_.includes(ALL_HASHES, options.digest)) { | ||
errors.push({ | ||
path: 'digest', | ||
message: `"${options.digest}" is not a valid HMAC hash digest.` | ||
}); | ||
} | ||
return errors; | ||
@@ -322,3 +337,4 @@ } | ||
* - decryptSync() | ||
* - list():Array | ||
* - listAlgorithms():Array | ||
* - listHashes():Array | ||
*/ | ||
@@ -380,3 +396,3 @@ | ||
*/ | ||
list() { | ||
listAlgorithms() { | ||
return ALL_CIPHERS; | ||
@@ -386,2 +402,12 @@ } | ||
/** | ||
* Lists all valid HMAC hashes. | ||
* | ||
* @returns {Array} | ||
* @access public | ||
*/ | ||
listHashes() { | ||
return ALL_HASHES; | ||
} | ||
/** | ||
* Gets NodeCipher defaults. | ||
@@ -463,4 +489,2 @@ * | ||
NodeCipher.Defaults = { | ||
input: undefined, | ||
output: undefined, | ||
password: undefined, | ||
@@ -467,0 +491,0 @@ salt: DEFAULT_SALT, // 'nodecipher' |
{ | ||
"name": "node-cipher", | ||
"version": "5.0.1", | ||
"version": "6.0.0", | ||
"description": "Securely encrypt sensitive files for use in public source control.", | ||
@@ -31,6 +31,10 @@ "main": "index.js", | ||
"dependencies": { | ||
"chalk": "^1.1.1", | ||
"commander": "^2.9.0", | ||
"debug": "^2.2.0", | ||
"fs-extra": "^0.26.4", | ||
"inquirer": "^0.11.2", | ||
"lodash": "^4.0.0", | ||
"validate": "^3.0.1" | ||
"validate": "^3.0.1", | ||
"yargs": "^3.32.0" | ||
}, | ||
@@ -41,4 +45,8 @@ "devDependencies": { | ||
"randomstring": "^1.1.3", | ||
"shelljs": "^0.5.3", | ||
"tmp": "0.0.28" | ||
}, | ||
"bin": { | ||
"nodecipher": "./bin/cli.js" | ||
} | ||
} |
184
README.md
@@ -6,4 +6,10 @@ node-cipher [![Build Status](https://travis-ci.org/nathanbuchar/node-cipher.svg?branch=master)](https://travis-ci.org/nathanbuchar/node-cipher) | ||
**Why should I use node-cipher?** | ||
**What is node-cipher?** | ||
Node-cipher is both a command line tool and a Node JS package which allows you to easily encrypt or decrypt files containing sensitive information. This way, you can safely add encrypted files to a public repository, even if they contain API keys and passwords. | ||
**Why would I use node-cipher?** | ||
Let's say you have a file in your project name `config.json` which contains sensitive information like private keys and database passwords. What should you do if you need to publicly host a repository containing this file? Certainly you wouldn't want to make the contents of `config.json` visible to the outside world. | ||
@@ -15,186 +21,40 @@ | ||
*** | ||
**:exclamation: If you're looking for the node-cipher command line tool, it has moved to [node-cipher-cli](http://github.com/nathanbuchar/node-cipher-cli).** | ||
*** | ||
Installation | ||
------------ | ||
Install | ||
------- | ||
**Command Line Interface** | ||
``` | ||
$ npm install node-cipher | ||
$ npm install -g node-cipher | ||
``` | ||
Options | ||
------- | ||
|Name|Type|Description|Required|Default| | ||
|:---|:--:|:----------|:------:|:-----:| | ||
|`input`|`string`|The file that you wish to encrypt or decrypt.|✓|| | ||
|`output`|`string`|The file that you wish to save the encrypted or decrypted contents to. This file does not necessarily need to exist beforehand.|✓|| | ||
|`password`|`string`|The password to use when deriving the encryption key.|✓|| | ||
|`salt`|`string`|The salt to use when deriving the encryption key.||`"nodecipher"`| | ||
|`iterations`|`number`|The number of iterations to use when deriving the key. The higher the number of iterations, the more secure the derived key will be, but will take a longer amount of time to complete.||`1000`| | ||
|`keylen`|`number`|The desired byte length for the derived key.||`512`| | ||
|`digest`|`string`|The HMAC digest algorithm with which to derive the key.||`"sha1"`| | ||
|`algorithm`|`string`|The cipher algorithm to use when encrypting or decrypting the input file. Use [`list()`](#list) to see a list of available cipher algorithms.||`"cast5-cbc"`| | ||
Methods | ||
------- | ||
* [`encrypt()`](#encrypt) | ||
* [`encryptSync()`](#encryptsync) | ||
* [`decrypt()`](#decrypt) | ||
* [`decryptSync()`](#decryptsync) | ||
* [`list()`](#list) | ||
*** | ||
### encrypt() | ||
##### `encrypt(options[, callback[, scope]])` | ||
Encrypts a file using the [options](#options) provided. Returns `undefined`. | ||
#### Parameters | ||
|Parameter|Type|Description|Required| | ||
|--------:|:--:|:----------|:------:| | ||
|`options`|`Object`|See [options](#options).|✓| | ||
|`callback`|`Function`|The function to call when the encryption has completed.|| | ||
|`scope`|`Object`|The scope for the `callback` function parameter, if provided.|| | ||
#### Example | ||
Encrypts `config.json` into `config.json.cast5` using the password `"passw0rd"`. | ||
```js | ||
let nodecipher = require('node-cipher'); | ||
nodecipher.encrypt({ | ||
input: 'config.json', | ||
output: 'config.json.cast5', | ||
password: 'passw0rd' | ||
}, function (err) { | ||
if (err) throw err; | ||
console.log('config.json encrypted.'); | ||
}); | ||
**Node JS** | ||
``` | ||
*** | ||
### encryptSync() | ||
##### `encryptSync(options)` | ||
The synchronous version of [`encrypt()`](#encrypt). Returns `undefined`. | ||
#### Parameters | ||
|Parameter|Type|Description|Required| | ||
|--------:|:--:|:----------|:------:| | ||
|`options`|`Object`|See [options](#options).|✓| | ||
#### Example | ||
Synchronously encrypts `config.json` into `config.json.cast5` using the password `"passw0rd"`. | ||
```js | ||
let nodecipher = require('node-cipher'); | ||
nodecipher.encryptSync({ | ||
input: 'config.json', | ||
output: 'config.json.cast5', | ||
password: 'passw0rd' | ||
}); | ||
$ npm install node-cipher | ||
``` | ||
*** | ||
### decrypt() | ||
##### `decrypt(options[, callback[, scope]])` | ||
Decrypts a file using the [options](#options) provided. Returns `undefined`. | ||
#### Parameters | ||
|Parameter|Type|Description|Required| | ||
|--------:|:--:|:----------|:------:| | ||
|`options`|`Object`|See [options](#options).|✓| | ||
|`callback`|`Function`|The function to call when the decryption has completed.|| | ||
|`scope`|`Object`|The scope for the `callback` function parameter, if provided.|| | ||
#### Example | ||
Decrypts `config.json.cast5` back into `config.json` using the password `"passw0rd"`. | ||
```js | ||
let nodecipher = require('node-cipher'); | ||
nodecipher.decrypt({ | ||
input: 'config.json.cast5', | ||
output: 'config.json', | ||
password: 'passw0rd' | ||
}, function (err) { | ||
if (err) throw err; | ||
console.log('config.json.cast5 decrypted.'); | ||
}); | ||
``` | ||
*** | ||
### decryptSync() | ||
##### `decryptSync(options)` | ||
Documentation | ||
------------- | ||
The synchronous version of [`decrypt()`](#decrypt). Returns `undefined`. | ||
The documentation is pretty extensive, and it's split into two pieces. | ||
#### Parameters | ||
|Parameter|Type|Description|Required| | ||
|--------:|:--:|:----------|:------:| | ||
|`options`|`Object`|See [options](#options).|✓| | ||
**How to use the Command Line Interface** | ||
[Documentation](https://github.com/nathanbuchar/node-cipher-cli/blob/master/docs/cli.md) | ||
#### Example | ||
**Using the Node JS API** | ||
[Documentation](https://github.com/nathanbuchar/node-cipher-cli/blob/master/docs/api.md) | ||
Synchronously decrypts `config.json.cast5` back into `config.json` using the password `"passw0rd"`. | ||
```js | ||
let nodecipher = require('node-cipher'); | ||
nodecipher.decryptSync({ | ||
input: 'config.json.cast5', | ||
output: 'config.json', | ||
password: 'passw0rd' | ||
}); | ||
``` | ||
*** | ||
### list() | ||
##### `list():Array` | ||
Debugging | ||
--------- | ||
Lists all available cipher algorithms as an Array. Returns `Array`. | ||
#### Example | ||
```js | ||
let nodecipher = require('node-cipher'); | ||
console.log(nodecipher.list()); | ||
// => ['CAST-cbc', 'aes-128-cbc', ..., 'seed-ofb'] | ||
``` | ||
*** | ||
Debug | ||
----- | ||
Node-cipher implements [debug](https://github.com/visionmedia/debug) for development logging. To set up node-cipher with debug, set the following environment variables: | ||
@@ -201,0 +61,0 @@ |
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
23699
9
766
8
5
82
+ Addedchalk@^1.1.1
+ Addedcommander@^2.9.0
+ Addedinquirer@^0.11.2
+ Addedyargs@^3.32.0
+ Addedansi-escapes@1.4.0(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcli-cursor@1.0.2(transitive)
+ Addedcli-width@1.1.1(transitive)
+ Addedcliui@3.2.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedexit-hook@1.1.1(transitive)
+ Addedfigures@1.7.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedinquirer@0.11.4(transitive)
+ Addedinvert-kv@1.0.0(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedlcid@1.0.0(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addedmute-stream@0.0.5(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonetime@1.1.0(transitive)
+ Addedos-locale@1.4.0(transitive)
+ Addedreadline2@1.0.1(transitive)
+ Addedrestore-cursor@1.0.1(transitive)
+ Addedrun-async@0.1.0(transitive)
+ Addedrx-lite@3.1.2(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedwindow-size@0.1.4(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedy18n@3.2.2(transitive)
+ Addedyargs@3.32.0(transitive)