Skip to content

Commit 13e3013

Browse files
committed
fix build
1 parent dd797ef commit 13e3013

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `email` on the `CleanupJob` table. All the data in the column will be lost.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "CleanupJob" DROP COLUMN "email";

apps/web/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ model CleanupJob {
475475
skipAttachment Boolean?
476476
skipConversation Boolean?
477477
478-
email String // deprecated
478+
// email String // deprecated
479479
emailAccountId String
480480
emailAccount EmailAccount @relation(fields: [emailAccountId], references: [id], onDelete: Cascade)
481481

apps/web/utils/crypto.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import crypto from "node:crypto";
2+
import { env } from "@/env";
3+
4+
const ALGORITHM = "aes-256-gcm";
5+
const SECRET_KEY = Buffer.from(env.OAUTH_LINK_STATE_SECRET, "hex"); // Ensure secret is 32 bytes hex encoded
6+
const IV_LENGTH = 16;
7+
const AUTH_TAG_LENGTH = 16;
8+
9+
export function encrypt(text: string): string {
10+
const iv = crypto.randomBytes(IV_LENGTH);
11+
const cipher = crypto.createCipheriv(ALGORITHM, SECRET_KEY, iv);
12+
const encrypted = Buffer.concat([
13+
cipher.update(text, "utf8"),
14+
cipher.final(),
15+
]);
16+
const authTag = cipher.getAuthTag();
17+
// Prepend IV and authTag to the encrypted data for storage
18+
return Buffer.concat([iv, authTag, encrypted]).toString("hex");
19+
}
20+
21+
export function decrypt(encryptedText: string): string | null {
22+
try {
23+
const buffer = Buffer.from(encryptedText, "hex");
24+
const iv = buffer.subarray(0, IV_LENGTH);
25+
const authTag = buffer.subarray(IV_LENGTH, IV_LENGTH + AUTH_TAG_LENGTH);
26+
const encrypted = buffer.subarray(IV_LENGTH + AUTH_TAG_LENGTH);
27+
28+
const decipher = crypto.createDecipheriv(ALGORITHM, SECRET_KEY, iv);
29+
decipher.setAuthTag(authTag);
30+
const decrypted = Buffer.concat([
31+
decipher.update(encrypted), // No encoding here, it's a buffer
32+
decipher.final(),
33+
]);
34+
return decrypted.toString("utf8");
35+
} catch (error) {
36+
// Log error appropriately if needed
37+
console.error("Decryption failed:", error);
38+
return null;
39+
}
40+
}

0 commit comments

Comments
 (0)