+
Skip to content

li0ard/belt

Repository files navigation

@li0ard/belt
BelT (STB 34.101.31) cipher implementation in pure TypeScript
docs




Installation

# from NPM
npm i @li0ard/belt

# from JSR
bunx jsr i @li0ard/belt

Supported modes

  • Electronic Codebook (ECB)
  • Cipher Block Chaining (CBC)
  • Counter (CTR)
  • Cipher Feedback (CFB)
  • Message Authentication Code (MAC)
  • Key wrapping (KWP)
  • Ctr-Hash-Encrypt (CHE / AEAD)
  • Datawrap (DWP / AEAD)
  • Compress function
  • Key expand function
  • Key transform function (KRP)
  • Blockwise disk encryption (BDE)
  • Sectorwise disk encryption (SDE)
  • Hash function (HASH)
  • Wide block (WBL)

Features

  • Provides simple and modern API
  • Most of the APIs are strictly typed
  • Fully complies with STB 34.101.31 (in Russian) standard
  • Supports Bun, Node.js, Deno, Browsers

Examples

ECB mode

import { encryptECB, decryptECB } from "@li0ard/belt";

let key = hexToBytes("E9DEE72C8F0C0FA62DDB49F46F73964706075316ED247A3739CBA38303A98BF6");
let pt = hexToBytes("b194bac80a08f53b366d008e584a5de48504fa9d1bb6c7ac252e72c202fdce0d5be3d61217b96181fe6786ad716b890b");
let ct = hexToBytes("69cca1c93557c9e3d66bc3e0fa88fa6e5f23102ef109710775017f73806da9dc46fb2ed2ce771f26dcb5e5d1569f9ab0");

console.log(encryptECB(key, pt));
console.log(decryptECB(key, ct));

CBC mode

import { encryptCBC, decryptCBC } from "@li0ard/belt";

let key = hexToBytes("E9DEE72C8F0C0FA62DDB49F46F73964706075316ED247A3739CBA38303A98BF6");
let iv = hexToBytes("BE32971343FC9A48A02A885F194B09A1");
let pt = hexToBytes("b194bac80a08f53b366d008e584a5de48504fa9d1bb6c7ac252e72c202fdce0d5be3d61217b96181fe6786ad716b890b");
let ct = hexToBytes("69cca1c93557c9e3d66bc3e0fa88fa6e5f23102ef109710775017f73806da9dc46fb2ed2ce771f26dcb5e5d1569f9ab0");

console.log(encryptCBC(key, pt, iv));
console.log(decryptCBC(key, ct, iv));

About

BelT (STB 34.101.31) cipher implementation in pure TypeScript

Topics

Resources

License

Stars

Watchers

Forks

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载