feat: add actual user for trpc wss-dev-server (#261)

* feat: add actual user for trpc wss-dev-server #233

* chore: address pull request feedback

* fix: deepsource issue
This commit is contained in:
Meier Lukas
2024-03-25 18:57:59 +01:00
committed by GitHub
parent 87808c1349
commit 058a8c4776
15 changed files with 174 additions and 69 deletions

View File

@@ -245,19 +245,27 @@ const key = Buffer.from(
//Encrypting text
export function encryptSecret(text: string): `${string}.${string}` {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv);
const initializationVector = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(
algorithm,
Buffer.from(key),
initializationVector,
);
let encrypted = cipher.update(text);
encrypted = Buffer.concat([encrypted, cipher.final()]);
return `${encrypted.toString("hex")}.${iv.toString("hex")}`;
return `${encrypted.toString("hex")}.${initializationVector.toString("hex")}`;
}
// Decrypting text
function decryptSecret(value: `${string}.${string}`) {
const [data, dataIv] = value.split(".") as [string, string];
const iv = Buffer.from(dataIv, "hex");
const initializationVector = Buffer.from(dataIv, "hex");
const encryptedText = Buffer.from(data, "hex");
const decipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv);
const decipher = crypto.createDecipheriv(
algorithm,
Buffer.from(key),
initializationVector,
);
let decrypted = decipher.update(encryptedText);
decrypted = Buffer.concat([decrypted, decipher.final()]);
return decrypted.toString();