Coder Social home page Coder Social logo

enc-service's Introduction

Encryption Service

HTTP based Encryption Service.

Getting Started

System Requirements

  • Nodejs
  • Npm
  • Relational Database(Postgres/Mysql)

Installing

npm i

DB Setup

  • Creating key type enum

    CREATE TYPE "enum_Keys_type" AS ENUM ('MASTER','OTHER');
    
  • Creating DB Table

    CREATE TABLE "Keys" (
      id SERIAL PRIMARY KEY,
      public text NOT NULL,
      private text NOT NULL,
      type "enum_Keys_type" NOT NULL,
      active boolean DEFAULT true NOT NULL,
      "createdAt" timestamp with time zone NOT NULL,
      "updatedAt" timestamp with time zone NOT NULL
    );
    

Generating keys

  1. Edit the DB credentials by exporting the following environment variables

    1. DB_HOST
    2. DB_USER
    3. DB_PASSWORD
    4. DB_NAME
    5. DB_DIALECT - "postgres"|"mysql"|"sqlite"
  2. Set the environment by exporting the NODE_ENV environment variable as development or prod

    1. DB_PORT defaults to 9999 in prod. If the DB server is listening on a different port, DB_PORT must be set.
  3. Run the key generation script

    node scripts/master.js

  • This will ask you for encryption password twice and then add the following
    • Encrypted RSA keys to the DB
  • The encryption password will be asked twice again -- same as above
    • Encrypted RSA keys in a file(./keys/keys.json)
  • The zip encryption password will be asked twice, this can be a different password
    • Protected zip of unencrypted keys (./keys/keys.zip)

Running the service

node app.js < passwd &

This will start the encryption service in the background on port 8013 by reading the master password from passwd file.

APIs

Encrypt

curl -X POST -H "Content-Type: application/json" -d '{
  "value":"sunbird"
}' "http://localhost:8013/encrypt"

curl -X POST -H "Content-Type: application/json" -d '{
    "value": { "name": "Ramesh Kumar", "phone": "9901990101" }
}' "http://localhost:8013/encrypt/obj"

Decrypt

curl -X POST -H "Content-Type: application/json" -d '{
  "value":"v1|62|DL6oW2QemDz/qmPcqP+mjD5x6Y6d2GGYkfeUHqyk9qazJ5O7Ep4bH06VX0D3iqQjckESFMXlE9nBDcy93JFVNw=="
}' "http://localhost:8013/decrypt"

curl -X POST -H "Content-Type: application/json" -d '{
  "value": { "name": "v1|62|DL6oW2QemDz/qmPcqP+mjD5x6Y6d2GGYkfeUHqyk9qazJ5O7Ep4bH06VX0D3iqQjckESFMXlE9nBDcy93JFVNw==",
             "phone": "v1|77|DL6oW2QemDz/qmPcqP+mjD5x6Y6d2GGYkfeUHqyk9qazJ5O7Ep4bH06VX0D3iqQjckESFMXlE9nBDcy93JFVNw=="}
}' "http://localhost:8013/decrypt/obj"

enc-service's People

Contributors

kochhar avatar

Watchers

 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.