Created
October 2, 2017 16:47
-
-
Save dwelch2344/958b956ebe1a0f1ec582ca8acd5d8684 to your computer and use it in GitHub Desktop.
Simple encryption using "ursa"
This file contains hidden or 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
'use strict'; | |
const fs = require('fs') | |
const ursa = require('ursa') | |
const home = require('os').homedir() | |
// if you need one, easy option: | |
// # openssl rsa -in ~/.ssh/id_rsa -outform pem > ~/.ssh/id_rsa.pem | |
// # openssl rsa -in ~/.ssh/id_rsa.pem -pubout > ~/.ssh/id_rsa.pub.pem | |
const pubKey = ursa.createPublicKey(fs.readFileSync(home + '/.ssh/id_rsa.pub.pem')) | |
const privKey = ursa.createPrivateKey(fs.readFileSync(home + '/.ssh/id_rsa.pem')) | |
const msg = "Hello, this is a test" | |
const enc = pubKey.encrypt(msg, 'utf8', 'base64') | |
console.log("enc \n", enc) | |
const dec = privKey.decrypt(enc, 'base64', 'utf8') | |
console.log("dec \n", dec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment