Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-cipher

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-cipher

Securely encrypt sensitive files for use in public source control.

  • 3.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-cipher

Securely encrypt sensitive files for use in public source control. Find on NPM.

Why would I want to encrypt my files?

Let's say you have a file in your project name config.json which contains sensitive information like private keys and database passwords.

What happens if you want 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, so instead you can use node-cipher to encrypt the file and add its encrypted counterpart to source control, which can later be decrypted using the encryption key when the repository is cloned.

Just don't forget to add the original config.json file to .gitignore!


Table of Contents


Install

$ npm install -g node-cipher

Command Line Interface

Looking for the Node JS API? Click here.

Usage

$ nodecipher [--list] <command> -i input -o output [-p password] [-a algorithm]

When in doubt, $ nodecipher --help

Commands

CommandDescription
encryptEncrypts a file using the arguments provided.
decryptDecrypts a file using the arguments provided.

Flags

FlagAliasDescriptionRequiredDefault
inputiThe input filename relative to the current working directory.
outputpThe output filename relative to the current working directory.
passwordpThe key that you will use to encrypt or decrypt your file. If this is not supplied directly, you will instead be prompted within your command line. If you are decrypting a file, the password must be the same as the one specified during encryption, or else the decryption will fail.
algorithmaThe cipher algorithm that you will use to encrypt or decrypt your file. If you are decrypting a file, the chosen algorithm must be the same as the one specified during encryption, or else the decryption will fail.cast5-cbc
listlLists all available cipher algorithms.
versionvShow the node-cipher version.
helphShow the help menu.

Example

Encrypts config.json into config.encrypted.json using the aes-128-cbc cipher algorithm.

$ nodecipher encrypt -i "config.json" -o "config.encrypted.json" -a aes-128-cbc

Node JS API

Looking for the CLI? Click here.

Options

NameTypeDescriptionRequiredDefault
inputstringThe input filename relative to the current working directory.
outputstringThe output filename relative to the current working directory.
passwordstringThe encryption password. Unlike the command line interface, this MUST be specified.
algorithmstringThe algorithm to use. Use nodecipher -l to see a list of available cipher algorithms."cast5-cbc"

Methods


encrypt(options[, callback[, scope]])

Encrypt a file using the options provided.

Parameters
ParameterTypeDescriptionRequired
optionsObjectThe NodeCipher options Object.
callbackFunctionThe function to call when the encryption has completed.
scopeObjectThe Function scope for the callback parameter, if provided.
Example

Encrypts config.json into config.encrypted.json using the password "b0sco".

let nodecipher = require('node-cipher');

nodecipher.encrypt({
  input: 'config.json',
  output: 'config.encrypted.json',
  password: 'b0sco'
}, function (err) {
  if (err) throw err;

  console.log('config.json encrypted.');
});

decrypt(options[, callback[, scope]])

Decrypts a file using the options provided.

Parameters
ParameterTypeDescriptionRequired
optionsObjectThe NodeCipher options Object.
callbackFunctionThe function to call when the decryption has completed.
scopeObjectThe Function scope for the callback parameter, if provided.
Example

Decrypts config.encrypted.json back into config.json using the password "b0sco".

let nodecipher = require('node-cipher');

nodecipher.decrypt({
  input: 'config.encrypted.json',
  output: 'config.json',
  password: 'b0sco'
}, function (err) {
  if (err) throw err;

  console.log('config.encrypted.json decrypted.');
});

list():Array

Lists all available cipher algorithms as an Array.

Example
let nodecipher = require('node-cipher');

console.log(nodecipher.list());
// => ['CAST-cbc', 'aes-128-cbc', ..., 'seed-ofb']

Tips

Using NPM, you can create custom scripts in our package.json file to automate much of the encryption/decryption process.

{
  // ...
  "scripts": {
    "encrypt": "nodecipher encrypt -i config.json -o config.encrypted.json",
    "decrypt": "nodecipher decrypt -i config.encrypted.json -o config.json"
  }
}

Simply run npm run encrypt or npm run decrypt to execute these commands.

Authors

License

MIT

Keywords

FAQs

Package last updated on 15 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc