MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / encryptForTest

Function encryptForTest

services/kiloclaw/src/utils/encryption.test.ts:18–36  ·  view source on GitHub ↗

* Helper: encrypt a string using the same RSA+AES envelope scheme * used by the shared lib (src/lib/encryption.ts). This allows us * to test decryption without importing the shared encryption module.

(value: string, publicKeyPem: string)

Source from the content-addressed store, hash-verified

16 * to test decryption without importing the shared encryption module.
17 */
18function encryptForTest(value: string, publicKeyPem: string): EncryptedEnvelope {
19 const dek = randomBytes(32);
20 const iv = randomBytes(16);
21 const cipher = createCipheriv('aes-256-gcm', dek, iv);
22 let encrypted = cipher.update(value, 'utf8');
23 encrypted = Buffer.concat([encrypted, cipher.final()]);
24 const authTag = cipher.getAuthTag();
25 const encryptedDataBuffer = Buffer.concat([iv, encrypted, authTag]);
26 const encryptedDEKBuffer = publicEncrypt(
27 { key: publicKeyPem, padding: constants.RSA_PKCS1_OAEP_PADDING, oaepHash: 'sha256' },
28 dek
29 );
30 return {
31 encryptedData: encryptedDataBuffer.toString('base64'),
32 encryptedDEK: encryptedDEKBuffer.toString('base64'),
33 algorithm: 'rsa-aes-256-gcm',
34 version: 1,
35 };
36}
37
38describe('encryption utilities', () => {
39 let publicKey: string;

Callers 1

encryption.test.tsFile · 0.70

Calls 2

updateMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected