node-noobcrypt

Node module providing easy methods for encryption.

npm install node-noobcrypt
6 downloads in the last week
7 downloads in the last month

node-noobcrypt

There are two types of encryption: one that will prevent your sister from reading your diary and one that will prevent your government.

  • Bruce Schneier

Problem

In the new era of Snowden and the NSA we need encryption tools accessible for everyone.

I really like ursa and I love encryption, but I wonder if anyone comes up quickly with a solution of encryptions buffer-length limitations. This module provides easy encryption for strings and buffers with any length!

It's quite useless for experienced users, but I hope with many following pull-requests it will help every user to develop an encrypted app quickly.

Install

npm install node-noobcrypt

Usage

var crypt = require('node-noobcrypt');
var keypair = crypt.generateKeypair(); // [ publicKey, privateKey ]

crypt.encrypt('Hello World!', keypair[0], function(data) {
    crypt.decrypt(data, keypair[1], function(decrypted) {
        console.log(decrypted.toString()); // Hello World!
    });
});

API

function generateKeypair()

Generates a new Keypair with a strength of 2048 bits and an exponent of 65537. Returns an array with two objects: The public key and the private key.

function encrypt(Buffer or String, Public Key, Callback(Data))

Encrypts a given buffer or string using a public key object. The encrypted data is returned via the callback function.

The encrypted data is a chain of base64 encoded strings joined by a '$'-sign.

function decrypt(String, Private Key, Callback(Data))

Decrypts encrypted data using a private key object. The decrypted data is returned via the callback function.

function publicKey(PEM)

Creates and returns a public key object from a given string in the PEM-format.

function privateKey(PEM)

Creates and returns a private key object from a given string in the PEM-format.

function getPublicPem(Public Key)

Creates and returns a string in the PEM-format from a given public key object.

function getPrivatePem(Private Key)

Creates and returns a string in the PEM-format from a given private key object.

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you