流量:
openpgp.key.readArmored
进行了解析Hey, encrypt me.
预期:明文已加密
实际:抛出以下错误
是否可以或者我需要再次阅读装有ascii的公钥并将其结果提供到options
中?
代码:
var recipients = getRecipients();
// recipients is a hashmap, key being pgp userId and value
// being the result of `await openpgp.key.readArmored(pubkey)`
// recipients = {
// 'bob <bob@email.com>': {
// { keys:
// [ { keyPacket: [Object],
// revocationSignatures: [],
// directSignatures: [],
// users: [Array],
// subKeys: [Array] } ] }
// }
// };
// define function to encrypt
const encrypt = async() => {
var options = {
message: openpgp.message.fromText('Hey, encrypt me.'),
publicKeys: recipients['bob <bob@email.com>'].keys
}
openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.data;
return encrypted;
})
.then(encrypted => {
console.log(encrypted);
});
});
encrypt();
错误:
UnhandledPromiseRejectionWarning: TypeError: Error encrypting message: key.getPrimaryUser is not a function
at /Users/rob/git/HandyEncryption/node_modules/openpgp/dist/openpgp.js:32694:35
at Array.map (<anonymous>)
at getPreferredAlgo (/Users/rob/git/HandyEncryption/node_modules/openpgp/dist/openpgp.js:32693:26)
at Message.encrypt (/Users/rob/git/HandyEncryption/node_modules/openpgp/dist/openpgp.js:33460:96)
at /Users/rob/git/HandyEncryption/node_modules/openpgp/dist/openpgp.js:34337:20
at process._tickCallback (internal/process/next_tick.js:68:7)