Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as eccrypto from 'eccrypto';
- import * as base58 from 'bs58';
- export async function testEncryptDecyptMessage() {
- const wif = "5JgbL2ZnoEAhTudReWH1RnMuQS6DBeLZt4ucV6t8aymVEuYg7sr";
- const pubKey = "EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg";
- const message = "secret message";
- // Last 4 of the EOS Keys are ripemd hash
- const privBuffer = base58.decode(wif).slice(1, 33);
- const pubBuffer = base58.decode(pubKey.slice(3)).slice(0, 33);
- // Encrypting the message for B.
- const encrypted = await eccrypto.encrypt(pubBuffer, Buffer.from(message));
- // Decrypting the message.
- const msgBuffer = await eccrypto.decrypt(privBuffer, encrypted);
- console.log("Decrypted Message:", msgBuffer.toString());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement