Giter Club home page Giter Club logo

mnemonic-cypher's Introduction

Mnemonic Cypher

The Mnemonic Cypher is a package that encrypts and decrypts data using mnemonic phrases.

The package implements an AES-256 encryption algorithm for data encryption and decryption. Although the mnemonic phrase is passed to the encrypt() and decrypt() methods, it isn't used as the secret key in the process. You can think of the mnemonic phrases as a public key through which the cypher algorithm can regenerate the secret key.

Installation

NPM
npm install @zheeno/mnemonic-cypher

Usage

Step 1: Import the Cypher class into your project like so

    const {Cypher} = require("@zheeno/mnemonic-cypher");

Step 2: Then create an instance of the Cypher class like so

    const cypher = new Cypher()

The Cypher class constructor accepts an optional wordLength argument of type integer (but defaults to 12) which specifies the number of words in the mnemonic phrase to be generated.

    //...
    const cypher = new Cypher()
    const { mnemonics } = cypher.genMnemonics()
    console.log("Mnemonics =>", mnemonics)

The above snippet generates a mnemonic phrase of 12 randomly selected words from the dictionary.

Step 3: Encrypt or decrypt data using the generated mnemonic phrase

    //...
    const testObj = {name: "Efezino", age: 28}
    // Encrypt data
    const testEnc = cypher.encrypt(testObj, mnemonics)
    // decrypt hex string
    const testDec = cypher.decrypt(testEnc, mnemonics)

Miscellaneous

The Cypher class instance exposes a couple of helper methods as listed below.

  • setWordLength(len):- This method accepts a single integer argument and sets the number of words to be generated in the mnemonic phrase. It is typically used before calling the genMnemonics() method.

  • secretFromPhrase(phrase):- Returns a string of the secret equivalent of the mnemonic phrase provided

  • phraseFromSecret(secret):- Returns a mnemonic phrase generated from the provided secret

mnemonic-cypher's People

Contributors

zheeno avatar

Stargazers

André avatar

Watchers

André 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.