i had try to test out an encryption stuff and im new to nodejs.
after several try and search over google, i unable to solve my problem. please help.
case: calling async method to encrypt data, however it return me with a Promise { <pending> }
im using npm openpgp
objective: return the ciphertext so i could use it for other purpose
my code as below: //execution.js
var tools = require('./tools');
console.log(tools.encrypt());
//tools.js
const openpgp = require('openpgp') // use as CommonJS, AMD, ES6 module or via window.openpgp
var fs = require('fs');
openpgp.initWorker({ path:'openpgp.worker.js' }) // set the relative web worker path
var pubkey = fs.readFileSync('public.key', 'utf8');
const passphrase = `super long and hard to guess secret` //what the privKey is encrypted with
module.exports = {
encrypt:async () =>{
const options = {
message: openpgp.message.fromText('Hello, World!'), // input as Message object
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for encryption
}
const encrypted = await openpgp.encrypt(options);
const ciphertext = encrypted.data;
fs.writeFile('message.txt',ciphertext ,'utf8', function (err) {
if (err) throw err;
console.log('msg written!');
});
return ciphertext;
},
decrypt: async function(){
// your code here
}
};
please help