feat: add hashing methods for email and IP in CryptoService for blind indexing
Introduced `hashEmail` and `hashIp` methods to enable searching on encrypted data. Added support to retrieve PGP encryption key from configuration.
This commit is contained in:
@@ -34,6 +34,31 @@ export class CryptoService {
|
||||
);
|
||||
}
|
||||
|
||||
// --- Blind Indexing (for search on encrypted data) ---
|
||||
|
||||
async hashEmail(email: string): Promise<string> {
|
||||
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<string> {
|
||||
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<string>("PGP_ENCRYPTION_KEY") || "default-pgp-key"
|
||||
);
|
||||
}
|
||||
|
||||
// --- Argon2 Hashing ---
|
||||
|
||||
async hashPassword(password: string): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user