({data, keyringId, unlockKey, encryptionKeyFprs, signingKeyFpr, uiLogSource, filename, noCache, allKeyrings})
| 182 | * @return {Promise<String>} - armored PGP message |
| 183 | */ |
| 184 | export async function encryptMessage({data, keyringId, unlockKey, encryptionKeyFprs, signingKeyFpr, uiLogSource, filename, noCache, allKeyrings}) { |
| 185 | const keyring = await getKeyringWithPrivKey(signingKeyFpr, keyringId, noCache); |
| 186 | if (!keyring) { |
| 187 | throw new MvError('No private key found', 'NO_PRIVATE_KEY_FOUND'); |
| 188 | } |
| 189 | await syncPublicKeys({keyring, keyIds: encryptionKeyFprs, keyringId, allKeyrings}); |
| 190 | try { |
| 191 | const result = await keyring.getPgpBackend().encrypt({data, keyring, unlockKey, encryptionKeyFprs, signingKeyFpr, armor: true, filename}); |
| 192 | await logEncryption(uiLogSource, keyring, encryptionKeyFprs); |
| 193 | return result; |
| 194 | } catch (e) { |
| 195 | console.log('getPgpBackend().encrypt() error', e); |
| 196 | if (e.code === 'PWD_DIALOG_CANCEL') { |
| 197 | throw e; |
| 198 | } |
| 199 | throw new MvError(l10n.get('encrypt_error', [e.message]), 'ENCRYPT_ERROR'); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Log encryption operation |
no test coverage detected