Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import * as eccrypto from 'eccrypto';
  2. import * as base58 from 'bs58';
  3.  
  4. export async function testEncryptDecyptMessage() {
  5. const wif = "5JgbL2ZnoEAhTudReWH1RnMuQS6DBeLZt4ucV6t8aymVEuYg7sr";
  6. const pubKey = "EOS6hMjoWRF2L8x9YpeqtUEcsDKAyxSuM1APicxgRU1E3oyV5sDEg";
  7. const message = "secret message";
  8.  
  9. // Last 4 of the EOS Keys are ripemd hash
  10. const privBuffer = base58.decode(wif).slice(1, 33);
  11. const pubBuffer = base58.decode(pubKey.slice(3)).slice(0, 33);
  12.  
  13. // Encrypting the message for B.
  14. const encrypted = await eccrypto.encrypt(pubBuffer, Buffer.from(message));
  15.  
  16. // Decrypting the message.
  17. const msgBuffer = await eccrypto.decrypt(privBuffer, encrypted);
  18.  
  19. console.log("Decrypted Message:", msgBuffer.toString());
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement