First hour with Law OSS
Orientation: what Law OSS is, the bring-your-own-key model that shapes every feature, and where the six agents and the monorepo actually live.
apps/api/src/services/encryption.ts25 lines · encrypt L10–16
1import * as aes from 'aes-js'
2import { createHash } from 'crypto'
3
4function getKey(): Uint8Array {
5 const secret = process.env.ENCRYPTION_SECRET!
6 const hash = createHash('sha256').update(secret).digest()
7 return new Uint8Array(hash)
8}
9
10export function encrypt(text: string): string {
11 const key = getKey()
12 const textBytes = aes.utils.utf8.toBytes(text)
13 const aesCtr = new aes.ModeOfOperation.ctr(key)
14 const encrypted = aesCtr.encrypt(textBytes)
15 return aes.utils.hex.fromBytes(encrypted)
16}
17
18export function decrypt(encryptedHex: string): string {
19 const key = getKey()
20 const encryptedBytes = aes.utils.hex.toBytes(encryptedHex)
21 const aesCtr = new aes.ModeOfOperation.ctr(key)
22 const decrypted = aesCtr.decrypt(encryptedBytes)
23 return aes.utils.utf8.fromBytes(decrypted)
24}
25