Skip to content

Commit

Permalink
wip: Test most basic error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 25, 2024
1 parent 4cc216f commit 4948164
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/utils/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ export function decrypt(
): string | undefined {
if (!secret) return undefined;

const [encryptedToken, iv] = secret.split(":");
const decipher = crypto.createDecipheriv(
"AES-256-CBC",
Buffer.from(key, "utf-8"),
Buffer.from(iv, "hex"),
);
let decryptedToken = decipher.update(encryptedToken, "hex", "utf-8");
decryptedToken += decipher.final("utf-8");
try {
const [encryptedToken, iv] = secret.split(":");
const decipher = crypto.createDecipheriv(
"AES-256-CBC",
Buffer.from(key, "utf-8"),
Buffer.from(iv, "hex"),
);
let decryptedToken = decipher.update(encryptedToken, "hex", "utf-8");
decryptedToken += decipher.final("utf-8");

return decryptedToken;
return decryptedToken;
} catch (error) {
console.error("Failed to decrypt secret");
return undefined;
}
}

0 comments on commit 4948164

Please sign in to comment.