Я пытаюсь зашифровать текст с помощью OpenPGP JS в приложении реакции.
У меня есть функция в классе реакции:
const openpgp = require('openpgp');
...
class XYZ extends React.Component{
...
async encrypt(text, targetKey){
await openpgp.initWorker({ path: 'openpgp.worker.js' });
var publicKey = (await openpgp.key.readArmored(targetKey.trim())).keys;
console.log(publicKey);
const result = await openpgp.encrypt({
message: openpgp.message.fromText(text),
publicKeys: publicKey
});
console.log(result.data);
}
...
const public_key = `-----BEGIN PGP PUBLIC KEY BLOCK----- .......`
const text = 'encrypt this'
this.encrypt(text, public_key);
для шифрования.
Я получаю сообщение об ошибке: Unhandled Rejection (Error): Error encrypting message: No keys, passwords, or session key provided.
Я обнаружил, что (await openpgp.key.readArmored(targetKey.trim())).keys;
возвращает пустой массив, не знаю почему.