Skip to content

pritamprasd/poc-encrypt-flask-reactjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

ECC based Encryption/Decryption in JS/wasm and python based app. [ecc, wasm, js, python, rust]

This is a demo project on encrypted communication between UI & backend over http/s, and delegating all heavy lifting(encryption in this case) to wasm binary compiled from ecies rust crate(https://docs.rs/ecies/0.2.1/ecies). The js binding for ecies wasm binary is handled with ecies-wasm npm package.

UI is built with reactjs and backend is a flask based api server. Encryption scheme being used: ecies(ECC based hybrid encryption).

Workflow:

Alt text

How ecies works?

ecies workflow

src: https://cryptobook.nakov.com/asymmetric-key-ciphers/ecies-public-key-encryption

  1. We start with V(senders pub-key) and m(plaintext message)
  2. A pair of ephemeral keypair is generated. U(public key), u(private key)
  3. A shared-secret is generated by V * u. Payload is encrypted with k_ENC(symmetric key derived from shared-secret). Here * is EC Point multiplication over finite fields(galios).

The whole deal about ECDH is, this shared-secret will be equal to U * v(senders private key)

  1. The final encrypted payload is : U, ciphertext(mac code, encrypted plaintext_message)

Performance of ecies lies in:

  • we only used symmetric encryption once,
  • and just relied on ECDH.
  • No expensive assymetric encryption at all.

How to start:

OR

  • Run server:
    • Generate privyte key with python eciespy_demo.py, save content as flask-app/keys/private.ec.key
      cd flask-app
      python3 -m venv venv
      source venv/bin/activate
      pip install -r requirements.txt
      python app.py
  • Run UI:
    • Update server host url in api.js
      cd ui-react-webapck
      yarn
      yarn start

Demo example:

  • Get age, msg as input, create JSON payload, encrypt using Public Key, convert encrypted data to base64.
  • call POST /data with payload
  • Server decrypts base64 encoded payload, decrypts using private-key, send age, msg back in response.

Notes:

About

An demo implementation of ECIES with flask and reactJS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published