Code Monkey home page Code Monkey logo

simple-e2ee's Introduction

@47ng/simple-e2ee

NPM MIT License Continuous Integration Coverage Status Dependabot Status

Simple end-to-end encryption for web apps. Inspired from Excalidraw and Firefox Send (RIP).

How it works

You encrypt your data in the browser, send the encrypted data to a server, and use the hash part of the URL (which never hits the server) to share the key with someone else.

On the other side, the recipient obtains the key from the URL, the payload from the server and decrypts the data.

This library does not handle any of the server upload/download side, it's up to you. It only deals with encryption, decryption and moving keys in and out of URLs.

Installation

$ yarn add @47ng/simple-e2ee
# or
$ npm i @47ng/simple-e2ee

Usage

import {
  encrypt,
  decrypt,
  applyKeyToURL,
  getKeyFromURL,
  generateKey
} from '@47ng/simple-e2ee'

// Before sending data to the server, encrypt it:
const { payload, key } = encrypt(
  "whatever you want, as long as it's JSON-serialisable"
)

// Upload `payload` to the server
// Stick the key onto the current URL:
const shareURL = applyKeyToURL(key)

// Optionally, apply the key to another URL
// (example, with an ID returned from the server):
const shareURL = applyKeyToURL(key, `https://example.com/share/${id}`)

// On the other side, get the key from the current URL,
// and the payload from the server:
const key = getKeyFromURL()
const message = decrypt(payload, key)

// Optionally, obtain the key from any URL:
const key = getKeyFromURL(
  `https://example.com/share/foo#KatLceVEOM2znzX_FGPKu6Zz1adWkhlq9b2R9WRjUsM=`
)

// Encrypt related pieces of content with the same key:
const payload = encrypt('some more data', key)

// Generate a key for later use:
const key = generateKey()

License

MIT - Made with ❤️ by François Best.

Using this package at work ? Sponsor me to help with support and maintenance.

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.