How To Secure Messages On EOS

Blockgenic
Aug 31, 2018 · 5 min read

A blockchain is a distributed ledger and every block of data is publicly available for everyone to see. You may be wondering what if I want to encrypt messages on blockchain, specifically, on EOS?

How securing messages on a blockchain works

We can incorporate NuCypher. NuCypher helps dApp developers store, share, and manage private data on public blockchains with decentralized proxy re-encryption as a service.

Here is how it works.

  1. Alice has sensitive data that she wants to be able to delegate access to.
  2. Alice encrypts her data using her own public key and stores it in the cloud, or decentralized storage.
  3. Alice delegates access to Bob. The data is rekeyed to Bob’s key in storage.
  4. Bob downloads the data and decrypts it with his private key.

Securing a message on EOS

We’ll start with the scenario where Alice and Bob both have access to the private key and Alice wants to send sensitive data to Bob, and leverage pyUmbral which is NuCypher’s reference implementation of Umbral (split-key threshold proxy re-encryption).

Let’s first build a message queue smart contract on EOS.

It construct one table called messages, which contains uint64_t msg_id, account_name from, account_name to, string ciphertext, and string capsule. msg_id is the primary key.

It provides two actions: sendmsg and deletemsg. sendmsg requires account_name from and to, msg_id, ciphertext and capsule. Ciphertext is the encrypted message and capsule is the concept in Umbral, which is generated using pyUmbral. deletemsgbasically takes a msg_id, verifies the given to account_name, then deletes the record.

Compile it:

Create an account to upload the smart contract:

Create test accounts alice and bob:


Let’s move on to build a client to encrypt/decrypt a message and interact with the smart contract.

  1. Generate a private key and write into a file.

2. Construct a parser

3. Read from the privkey file.

3. Encrypt a message and send it.

3. Read from messages table, if to matches read_msg_to, decrypt a message and then delete it.

4. Default values.

Let’s wrap them up and test!

Check the messages table.

The encrypted message is there. Then let’s read it.

Check the messages table, the message is gone.

Thus we explored how to secure messages on EOS. Moving forward, we can work on scenario where Alice and Bob have their own keys, or send to multiple users.

Our socials

Website
Twitter
Youtube
Meetup
Steem

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Blockgenic

Written by

We are a firm focused on Enterprise adoption of blockchain technology. EOS Block Producer name: ‘blockgenicbp’. www.blockgenic.io

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade