MCPcopy Index your code
hub / github.com/mailvelope/mailvelope / encrypt

Function encrypt

src/modules/openpgpjs.js:69–86  ·  view source on GitHub ↗
({data, dataURL, keyring, unlockKey, encryptionKeyFprs, signingKeyFpr, filename, armor})

Source from the content-addressed store, hash-verified

67 * @return {String|Uint8Array}
68 */
69export async function encrypt({data, dataURL, keyring, unlockKey, encryptionKeyFprs, signingKeyFpr, filename, armor}) {
70 let signingKey;
71 let message;
72 if (data) {
73 message = await createMessage({text: data, filename});
74 } else if (dataURL) {
75 const content = dataURL2str(dataURL);
76 data = str2Uint8Array(content);
77 message = await createMessage({binary: data, filename});
78 }
79 if (signingKeyFpr) {
80 signingKey = keyring.getPrivateKeyByIds(signingKeyFpr);
81 signingKey = await unlockKey({key: signingKey});
82 }
83 const keys = keyring.getKeysByFprs(encryptionKeyFprs);
84 const result = await pgpEncrypt({message, encryptionKeys: keys, signingKeys: signingKey, format: armor ? 'armored' : 'binary'});
85 return armor ? result : Uint8Array2str(result);
86}
87
88/**
89 * Sign cleartext message

Callers

nothing calls this directly

Calls 6

dataURL2strFunction · 0.90
str2Uint8ArrayFunction · 0.90
Uint8Array2strFunction · 0.90
getPrivateKeyByIdsMethod · 0.80
getKeysByFprsMethod · 0.80
unlockKeyFunction · 0.70

Tested by

no test coverage detected