-
-
Save hedgerh/c6e60092daf67ccc3ebdca728518a958 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
var openpgp = require('openpgp'); // use as CommonJS | |
var path = require('path'); | |
//var __dirname = '/home/evan/Documents/jeff/node/jb'; | |
var worker_path = path.join(__dirname, 'node_modules', 'openpgp','worker', 'worker.js'); | |
openpgp.initWorker({ path: worker_path }); // set the relative web worker path | |
openpgp.config.aead_protect = true; // activate fast AES-GCM mode (not yet OpenPGP standard) | |
var fs = require('fs'); | |
module.exports = function(cb) { | |
fs.readFile('/home/evan/postgres.gpg',function read(err, encrypted) { | |
if (err) { | |
throw err; | |
} | |
var options = { | |
message: openpgp.message.read(encrypted), // parse encrypted bytes | |
password: 'em', // decrypt with password | |
format: 'utf8' // output as utf8 string | |
}; | |
openpgp.decrypt(options).then(function(plaintext) { | |
// console.log(plaintext); | |
var db_pass = plaintext.data.toLocaleString('utf-8'); | |
// console.log(db_pass); | |
var connectStaticString = 'postgres://postgres:' + db_pass + '@localhost:5432/harlem'; | |
var connectionString = process.env.DATABASE_URL || connectStaticString; | |
console.log(connectionString); | |
cb(connectionString); // utf8 string | |
}); | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment