Skip to content

Instantly share code, notes, and snippets.

@hedgerh
Created July 1, 2016 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hedgerh/c6e60092daf67ccc3ebdca728518a958 to your computer and use it in GitHub Desktop.
Save hedgerh/c6e60092daf67ccc3ebdca728518a958 to your computer and use it in GitHub Desktop.
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