javascript - Openpgpjs 不会读取密钥
问题描述
我正在尝试在反应应用程序中使用 OpenPGPJS 加密文本。
我在反应类中有一个功能:
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;
返回空数组,我知道为什么。
解决方案
推荐阅读
- asp.net-core - 使用 IdentityServer4 使用授权中间件保护静态文件
- flutter - 孩子有非零弹性,但传入的高度约束是无界的
- angular - 如何将不以任何符号分隔、以几个(无用)零结尾的长日期字符串转换为 dd/mm/yyyy 格式?
- soap - 如何从模拟中获取最后一个请求?
- autohotkey - autohotkey 中是否有任何脚本可以从 quickbooks 下载报告
- reactjs - 查询带有特定文本的按钮
- arduino - 当我创建一个功能,一旦激活,就会回复短信
- python - Python中的变换矩阵
- git - Git - 如何从远程重新设置的分支中提取最新更改
- typescript - 为什么 TypeScript 接口不支持索引签名而类型别名支持?