Попытка зашифровать строку, используя открытый ключ, который не в формате ascii-armored

Поток:

  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 ответов

Другие вопросы по тегам