Code Monkey home page Code Monkey logo

cyphering's Introduction

Cyphering

plug and play cyphering system for Javascript

Note

This library was developed to make it easy for developer to create public and private key and store it easily. It is also easy to use utility to encrypt or decrypt your message message. My main objective was solve common issues which developer might face for working with crypto package. You can save the public key and private key or encrypt or decrypt your data by using this package.

Usage

In order to generate public key and private key or encrypt and decrypt a message, please follow below steps:

At the root of your project, do:

npm install cyphering  --save

Then in your project:

const Cyphering = require('cyphering');

Methods

All the methods return promise.

Generate Public and Private keys Method:

This functionality is used for generating public and private key. it works Async. The output of this function will be json parameter which is contain your public key and private key. Please don't forget to store your passPhrase since you need it for decryption process.

Function:
Cyphering.generatePublicAndPrivateKey(params)
Input:
params: {
    "passphrase": "string"
}
Output:
{
    "publicKey": "string",
    "privateKey": "string"
}

Encryption Method:

This function is used to encrypt your 'data' by using a public key. The output of this function is encryptedData.

Function:
Cyphering.encryption(params)
Input:
params: {
    "data": "string",
    "publicKey": "string"
}
Output:
    "encryptedData": "string"

Decryption Method:

This function is used to decrypt the encrypted data. You need to provide your encrypted data, private key and passPhrase to decrypt the data. The output of this function will be decryptedData.

Function:
Cyphering.decryption(params)
Input:
params: {
    "encryptedData": "string",
    "privateKey": "string",
    "passphrase": "string"
}
Output:
    "decryptedData": "string"    

Error codes

The error codes are the standard error codes as returned by crypto library.

Example

const Cyphering = require('cyphering');

async function test() {

    try {
        const passphrase = "my passphrase";

        let params = {
            passphrase
        };

        const keys = await Cyphering.generatePublicAndPrivateKey(params);

        let data = "I love to play xbox.";

        let encryptParams = {
            data: data,
            publicKey: keys.publicKey
        }

        const encryptedData = Cyphering.encryption(encryptParams);

        let decryptParams = {
            encryptedData: encryptedData,
            privateKey: keys.privateKey,
            passphrase: passphrase
        };

        const decryptedData = Cyphering.decryption(decryptParams);

        console.log('Your initial message was: ' + data);
        console.log('Your encrypted message was: ' + encryptedData);
        console.log('Your decrypted message is: ' + decryptedData);
    } catch (err) {
        console.log(err);
    }
}

test();

cyphering's People

Contributors

day2daychallenge avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.