get creation of links working

This commit is contained in:
2024-10-02 18:01:54 -04:00
parent d98f589031
commit 2b63dc62fc
15 changed files with 659 additions and 123 deletions

View File

@@ -0,0 +1,23 @@
import { Service } from "@tsed/di";
import crypto from "crypto";
@Service()
export class EncryptionService {
private algorithm = 'aes-256-cbc';
private key = crypto.randomBytes(32);
async encrypt(text: string): Promise<{ encryptedText: string; iv: string }> {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(this.algorithm, this.key, iv);
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
return { encryptedText: encrypted, iv: iv.toString('hex') };
}
async decrypt(encryptedText: string, iv: string): Promise<string> {
const decipher = crypto.createDecipheriv(this.algorithm, this.key, Buffer.from(iv, 'hex'));
let decrypted = decipher.update(encryptedText, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
}