diff --git a/backend/src/crypto/crypto.service.ts b/backend/src/crypto/crypto.service.ts index 50e96b5..a68ab2e 100644 --- a/backend/src/crypto/crypto.service.ts +++ b/backend/src/crypto/crypto.service.ts @@ -34,6 +34,31 @@ export class CryptoService { ); } + // --- Blind Indexing (for search on encrypted data) --- + + async hashEmail(email: string): Promise { + const normalizedEmail = email.toLowerCase().trim(); + const data = new TextEncoder().encode(normalizedEmail); + const hashBuffer = await crypto.subtle.digest("SHA-256", data); + return Array.from(new Uint8Array(hashBuffer)) + .map((b) => b.toString(16).padStart(2, "0")) + .join(""); + } + + async hashIp(ip: string): Promise { + const data = new TextEncoder().encode(ip); + const hashBuffer = await crypto.subtle.digest("SHA-256", data); + return Array.from(new Uint8Array(hashBuffer)) + .map((b) => b.toString(16).padStart(2, "0")) + .join(""); + } + + getPgpEncryptionKey(): string { + return ( + this.configService.get("PGP_ENCRYPTION_KEY") || "default-pgp-key" + ); + } + // --- Argon2 Hashing --- async hashPassword(password: string): Promise {