({plainFile, keyringId, unlockKey, encryptionKeyFprs, signingKeyFpr, uiLogSource, armor, noCache, allKeyrings})
| 483 | * @return {String} - encrypted file as armored block or JS binary string |
| 484 | */ |
| 485 | export async function encryptFile({plainFile, keyringId, unlockKey, encryptionKeyFprs, signingKeyFpr, uiLogSource, armor, noCache, allKeyrings}) { |
| 486 | const keyring = await getKeyringWithPrivKey(signingKeyFpr, keyringId, noCache); |
| 487 | if (!keyring) { |
| 488 | throw new MvError('No private key found', 'NO_PRIVATE_KEY_FOUND'); |
| 489 | } |
| 490 | await syncPublicKeys({keyring, keyIds: encryptionKeyFprs, keyringId, allKeyrings}); |
| 491 | try { |
| 492 | const result = await keyring.getPgpBackend().encrypt({dataURL: plainFile.content, keyring, unlockKey, encryptionKeyFprs, signingKeyFpr, armor, filename: plainFile.name}); |
| 493 | await logEncryption(uiLogSource, keyring, encryptionKeyFprs); |
| 494 | return result; |
| 495 | } catch (error) { |
| 496 | console.log('pgpmodel.encryptFile() error', error); |
| 497 | if (error.code === 'PWD_DIALOG_CANCEL') { |
| 498 | throw error; |
| 499 | } |
| 500 | throw new MvError(l10n.get('encrypt_error', [error.message]), 'ENCRYPT_ERROR'); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Decrypt File |
no test coverage detected