Change encrypt symmetrical split character

This commit is contained in:
Dominik Korsa 2021-01-23 15:17:36 +01:00
parent ca78ddc078
commit 5a5facdf40
No known key found for this signature in database
GPG key ID: 546F986F71A6FE6E

View file

@ -27,11 +27,11 @@ export function encryptSymmetrical(value: string, key: string): string {
const ivBuffer = crypto.randomBytes(16); const ivBuffer = crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-cbc', base64url.toBuffer(key), ivBuffer); const cipher = crypto.createCipheriv('aes-256-cbc', base64url.toBuffer(key), ivBuffer);
const encrypted = Buffer.concat([cipher.update(value), cipher.final()]); const encrypted = Buffer.concat([cipher.update(value), cipher.final()]);
return `${base64url.encode(encrypted)}@${base64url.encode(ivBuffer)}`; return `${base64url.encode(encrypted)}.${base64url.encode(ivBuffer)}`;
} }
export function decryptSymmetrical(encrypted: string, key: string): string { export function decryptSymmetrical(encrypted: string, key: string): string {
const [encryptedData, iv] = encrypted.split('@'); const [encryptedData, iv] = encrypted.split('.');
const ivBuffer = base64url.toBuffer(iv); const ivBuffer = base64url.toBuffer(iv);
const encryptedBuffer = base64url.toBuffer(encryptedData); const encryptedBuffer = base64url.toBuffer(encryptedData);
const decipher = crypto.createDecipheriv('aes-256-cbc', base64url.toBuffer(key), ivBuffer); const decipher = crypto.createDecipheriv('aes-256-cbc', base64url.toBuffer(key), ivBuffer);