MCPcopy Create free account
hub / github.com/WinterTC55/iter-streams / decryptMessage

Function decryptMessage

samples/15-encryption.ts:1109–1120  ·  view source on GitHub ↗
(password: string, envelope: Uint8Array)

Source from the content-addressed store, hash-verified

1107 }
1108
1109 async function decryptMessage(password: string, envelope: Uint8Array): Promise<string> {
1110 const salt = envelope.slice(0, 16);
1111 const iv = envelope.slice(16, 28);
1112 const ciphertext = envelope.slice(28, envelope.length - 16);
1113 const authTag = envelope.slice(envelope.length - 16);
1114
1115 const key = await deriveKey(password, salt);
1116
1117 return Stream.text(
1118 Stream.pull(Stream.from(ciphertext), createAes256GcmDecryptTransform(key, { iv, authTag }))
1119 );
1120 }
1121
1122 const password = 'my-secret';
1123 const message = 'Complete encrypted message using Stream.pull()!';

Callers 1

mainFunction · 0.85

Calls 3

deriveKeyFunction · 0.85
pullMethod · 0.65

Tested by

no test coverage detected