UNPKG

@li0ard/kuznyechik

Version:

Kuznyechik cipher implementation in pure TypeScript

27 lines (26 loc) 857 B
import { Kuznyechik, BLOCK_SIZE } from "../"; import { ecb_encrypt, ecb_decrypt } from "@li0ard/gost3413"; /** * Encrypts data using Electronic Codebook (ECB) mode with Kuznyechik cipher. * * @param key Encryption key * @param data Data to be encrypted * @returns {Uint8Array} */ export const encryptECB = (key, data) => { const cipher = new Kuznyechik(key); const encrypter = (buf) => cipher.encryptBlock(buf); return ecb_encrypt(encrypter, BLOCK_SIZE, data); }; /** * Decrypts data using Electronic Codebook (ECB) mode with Kuznyechik cipher. * * @param key Encryption key * @param data Data to be decrypted * @returns {Uint8Array} */ export const decryptECB = (key, data) => { const cipher = new Kuznyechik(key); const decrypter = (buf) => cipher.decryptBlock(buf); return ecb_decrypt(decrypter, BLOCK_SIZE, data); };