Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
Last active February 10, 2023 16:24
Show Gist options
  • Save AvocadoVenom/71371b96c2c884fc0f04c476a78a3d15 to your computer and use it in GitHub Desktop.
Save AvocadoVenom/71371b96c2c884fc0f04c476a78a3d15 to your computer and use it in GitHub Desktop.
import TextManipulationHelper from './text-manipulation';
import CryptographyService from './cryptography.service';
const decrypt = async (cipherText: string, secretKey: string, initialVector: string) => {
const keyBuffer = TextManipulationHelper.convertBase64ToStream(secretKey);
const decryptionKey = await CryptographyService.parseKey(keyBuffer);
const cipherBuffer = TextManipulationHelper.convertBase64ToStream(cipherText);
const ivBuffer = TextManipulationHelper.convertBase64ToStream<Uint8Array>(initialVector);
return await CryptographyService.decrypt(cipherBuffer, decryptionKey, ivBuffer)
};
const cipher = 'base64-encrypted-content';
const key = 'base64-encrpytion-key';
const iv = 'base64-initial-vector';
const plainText = decrypt(cipher, key, iv);
console.log(plainText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment