Last active
November 17, 2019 22:14
-
-
Save yaodong/f71eec4edf468f6ae9091bc39dfa3661 to your computer and use it in GitHub Desktop.
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 fs = require('fs') | |
const crypto = require('crypto') | |
const publicKey = fs.readFileSync('public.pem') | |
const privateKey = fs.readFileSync('private.pem') | |
const message = 'Hello, world!' | |
const encryptedMsg = crypto.publicEncrypt(publicKey, Buffer.from(message, 'utf8')) | |
console.log('encrypted by private key: ' + encryptedMsg.toString('hex')) | |
const decryptedMsg = crypto.privateDecrypt(privateKey, encryptedMsg); | |
console.log('decrypted by public key: ' + decryptedMsg.toString('utf8')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment