How To Secure Messages On EOS

Blockgenic
Coinmonks
5 min readAug 31, 2018

--

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

Written by Yannick Slenter for Blockgenic

--

--

Blockgenic
Coinmonks

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