Created
January 18, 2020 15:48
-
-
Save ademcan/21fbe9e56dbd4ae1b3e98f1be0f314d9 to your computer and use it in GitHub Desktop.
EMS_partA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create new Kyber objects | |
const KYBOBJECT = await new KYBLIB.Kyber.empty() | |
// Take a 32 byte seed, s | |
const s = Crypto.randomBytes(32) | |
// Create a random 32 byte key, k | |
const k = Crypto.randomBytes(32) | |
var textBytes = aesjs.utils.utf8.toBytes(s) | |
var aesCtr = new aesjs.ModeOfOperation.ctr(k) | |
// AES256 encrypt s with k to create payload, p | |
var p = aesCtr.encrypt(textBytes) | |
const aespk = Buffer.from(k.toString('hex')) | |
// Kyber encode k to ke | |
KYBOBJECT.kem_encode(aespk) | |
const ke = KYBOBJECT.getCypherText() | |
// Generating ECIES key pair (we will retrieve them from the chain) | |
var privateKey = eccrypto.generatePrivate() | |
var publicKey = eccrypto.getPublic(privateKey) | |
// ECIES encrypt ke to kee | |
eccrypto.encrypt(publicKey, Buffer.from(ke)).then(function (kee) { | |
spinner.succeed('DONE') | |
// sending kee and p to Recipient | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment