MCPcopy
hub / github.com/simstudioai/sim / encrypt

Function encrypt

packages/security/src/encryption.ts:11–29  ·  view source on GitHub ↗
(
  plaintext: string,
  key: Buffer
)

Source from the content-addressed store, hash-verified

9 * @param key - 32-byte encryption key
10 */
11export async function encrypt(
12 plaintext: string,
13 key: Buffer
14): Promise<{ encrypted: string; iv: string }> {
15 assertKey(key)
16
17 const iv = randomBytes(16)
18 const cipher = createCipheriv('aes-256-gcm', key, iv, { authTagLength: 16 })
19 let encrypted = cipher.update(plaintext, 'utf8', 'hex')
20 encrypted += cipher.final('hex')
21
22 const authTag = cipher.getAuthTag()
23 const ivHex = iv.toString('hex')
24
25 return {
26 encrypted: `${ivHex}:${encrypted}:${authTag.toString('hex')}`,
27 iv: ivHex,
28 }
29}
30
31/**
32 * AES-256-GCM decryption primitive. Expects input produced by {@link encrypt}

Callers 3

encryption.test.tsFile · 0.90
encryptApiKeyFunction · 0.90
encryptSecretFunction · 0.90

Calls 2

assertKeyFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected