Skip to content

Instantly share code, notes, and snippets.

@dwelch2344
Created October 2, 2017 16:47
Show Gist options
  • Save dwelch2344/958b956ebe1a0f1ec582ca8acd5d8684 to your computer and use it in GitHub Desktop.
Save dwelch2344/958b956ebe1a0f1ec582ca8acd5d8684 to your computer and use it in GitHub Desktop.
Simple encryption using "ursa"
'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