MCPcopy
hub / github.com/mailvelope/mailvelope / symEncrypt

Function symEncrypt

src/modules/crypto.js:26–51  ·  view source on GitHub ↗
(msg, passphrase)

Source from the content-addressed store, hash-verified

24 * @return {openpgp.Message} new message with encrypted content
25 */
26export async function symEncrypt(msg, passphrase) {
27 if (!passphrase) {
28 throw new Error('The passphrase cannot be empty!');
29 }
30 const sessionKeyAlgorithm = enums.symmetric.aes256;
31 const packetlist = new PacketList();
32 // create a Symmetric-key Encrypted Session Key (ESK)
33 const symESKPacket = new SymEncryptedSessionKeyPacket();
34 symESKPacket.version = 4;
35 symESKPacket.sessionKeyAlgorithm = sessionKeyAlgorithm;
36 // call encrypt one time to init S2K
37 await symESKPacket.encrypt('123456');
38 symESKPacket.sessionKey = null;
39 symESKPacket.encrypted = null;
40 // call decrypt to generate the session key
41 await symESKPacket.decrypt(passphrase);
42 packetlist.push(symESKPacket);
43 // create integrity protected packet
44 const symEncryptedPacket = new SymEncryptedIntegrityProtectedDataPacket();
45 symEncryptedPacket.packets = msg.packets;
46 await symEncryptedPacket.encrypt(sessionKeyAlgorithm, symESKPacket.sessionKey);
47 packetlist.push(symEncryptedPacket);
48 // remove packets after encryption
49 symEncryptedPacket.packets = new PacketList();
50 return new Message(packetlist);
51}
52
53/**
54 * Return a secure random number in the specified range

Callers 2

crypto-test.jsFile · 0.90
createPrivateKeyBackupFunction · 0.90

Calls 3

decryptMethod · 0.80
encryptMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected