Created
February 11, 2022 21:13
-
-
Save alexneamtu/74d3fb0e5dae93d0fbcd0f7a5a909353 to your computer and use it in GitHub Desktop.
Ecies
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
const { privateDecrypt } = require('crypto'); | |
const eccrypto = require('eccrypto'); | |
const oldPrivateKey = '-----BEGIN PRIVATE KEY-----\n' + | |
///PRIVATE KEY CODE | |
'-----END PRIVATE KEY-----'; | |
const data = 'some base64'; | |
const decryptpedDoc = privateDecrypt(oldPrivateKey, Buffer.from(data, 'base64')); | |
const decryptpedDocString = decryptpedDoc.toString(); | |
const privateKeyA = eccrypto.generatePrivate(); | |
console.log(privateKeyA.toString('hex')); | |
const publicKeyA = eccrypto.getPublic(privateKeyA); | |
console.log(publicKeyA.toString('hex')); | |
const privateKeyB = eccrypto.generatePrivate(); | |
console.log(privateKeyB.toString('hex')); | |
const publicKeyB = eccrypto.getPublic(privateKeyB); | |
console.log(publicKeyB.toString('hex')); | |
// Encrypting the message for B. | |
eccrypto.encrypt(publicKeyB, Buffer.from(decryptpedDocString)).then(function (encrypted) { | |
// B decrypting the message. | |
eccrypto.decrypt(privateKeyB, encrypted).then(function (plaintext) { | |
console.log('Message to part B:', plaintext.toString()); | |
}); | |
}); | |
// Encrypting the message for A. | |
eccrypto.encrypt(publicKeyA, Buffer.from(decryptpedDocString)).then(function (encrypted) { | |
// A decrypting the message. | |
eccrypto.decrypt(privateKeyA, encrypted).then(function (plaintext) { | |
console.log('Message to part A:', plaintext.toString()); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment