Experimental pretty path

This commit is contained in:
Arief Rachmawan
2023-04-29 20:12:36 +07:00
parent 6777aadc03
commit b12dfed44a
14 changed files with 463 additions and 195 deletions
+17
View File
@@ -57,3 +57,20 @@ export function decrypt(encryptedData: string, encryptionKey: string) {
decrypted = Buffer.concat([decrypted, decipher.final()]);
return decrypted.toString();
}
const urlIV = crypto.randomBytes(16);
const urlKey = process.env.ENCRYPTION_KEY?.slice(0, 16) || "gudora-index9534";
export function urlEncrypt(fileId: string): string {
const cipher = crypto.createCipheriv("aes-128-cbc", urlKey, urlIV);
let cipherText = cipher.update(fileId, "utf8", "hex");
cipherText += cipher.final("hex");
return cipherText;
}
export function urlDecrypt(chiperText: string): string {
const decipher = crypto.createDecipheriv("aes-128-cbc", urlKey, urlIV);
let plainText = decipher.update(chiperText, "hex", "utf8");
plainText += decipher.final("utf8");
return plainText;
}