尝试使用非ASCII装甲格式的公钥加密字符串

时间:2018-11-28 15:25:58

标签: javascript node.js openpgp.js

流量:

  1. 获取存储的PGP密钥
  2. 这些不是ASCII装甲的键,它们已经使用openpgp.key.readArmored进行了解析
  3. 尝试加密文本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)

0 个答案:

没有答案