@li0ard/kuznyechik
Version:
Kuznyechik cipher implementation in pure TypeScript
25 lines (24 loc) • 845 B
JavaScript
import { BLOCK_SIZE, Kuznyechik } from "../index.js";
import { cbc_encrypt, cbc_decrypt } from "@li0ard/gost3413";
/**
* Encrypts data using Cipher Block Chaining (CBC) mode with the Kuznyechik cipher.
*
* @param key Encryption key
* @param data Data to be encrypted
* @param iv Initialization vector
*/
export const encryptCBC = (key, data, iv) => {
const cipher = new Kuznyechik(key);
return cbc_encrypt(cipher.encryptBlock.bind(cipher), BLOCK_SIZE, data, iv);
};
/**
* Decrypts data using Cipher Block Chaining (CBC) mode with the Kuznyechik cipher.
*
* @param key Encryption key
* @param data Data to be decrypted
* @param iv Initialization vector
*/
export const decryptCBC = (key, data, iv) => {
const cipher = new Kuznyechik(key);
return cbc_decrypt(cipher.decryptBlock.bind(cipher), BLOCK_SIZE, data, iv);
};