HTTP based Encryption Service.
- Nodejs
- Npm
- Relational Database(Postgres/Mysql)
npm i
-
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 );
-
Edit the DB credentials by exporting the following environment variables
- DB_HOST
- DB_USER
- DB_PASSWORD
- DB_NAME
- DB_DIALECT - "postgres"|"mysql"|"sqlite"
-
Set the environment by exporting the
NODE_ENV
environment variable asdevelopment
orprod
- DB_PORT defaults to 9999 in prod. If the DB server is listening on a different port, DB_PORT must be set.
-
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)
node app.js < passwd &
This will start the encryption service in the background on port 8013 by reading the master password from passwd
file.
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"
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"