Я пытался протестировать шифрование, и я новичок в nodejs.
после нескольких попыток поиска по Google, я не могу решить свою проблему.
пожалуйста, помогите.
case: вызов асинхронного метода для шифрования данных, однако он возвращает мне Promise { <pending> }
я использую npm openpgp
цель: вернуть зашифрованный текст, чтобы я мог использовать его для других целей
мой код, как показано ниже:
//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
}
};
пожалуйста, помогите