MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / encrypt

Function encrypt

packages/auth-server/src/server/crypto.ts:11–22  ·  view source on GitHub ↗
(dataToEncrypt: string)

Source from the content-addressed store, hash-verified

9const SECRET = process.env.NEXTAUTH_SECRET!;
10
11export function encrypt(dataToEncrypt: string): string {
12 if (!SECRET) {
13 throw new Error('missing secret');
14 }
15 const salt = randomBytes(16).toString('hex');
16 const key = scryptSync(SECRET, salt, 32);
17 const iv = Buffer.alloc(16, 0); // Initialization vector.
18 const cipher = createCipheriv(algorithm, key, iv);
19 let encrypted = cipher.update(dataToEncrypt, 'utf8', 'hex');
20 encrypted += cipher.final('hex');
21 return `${salt}:${encrypted}`;
22}
23
24export function decrypt(dataToDecrypt: string): string {
25 if (!SECRET) {

Callers 1

CreateRouterFunction · 0.90

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected