Skip to content

li0ard/des

Repository files navigation

@li0ard/des
DES cipher implementation in pure TypeScript
docs




Installation

# from NPM
npm i @li0ard/des

# from JSR
bunx jsr i @li0ard/des

Supported algorithms

  • Classic DES
  • 3DES-EDE

Supported modes

  • Electronic Codebook (ECB)
  • Cipher Block Chaining (CBC)
  • Cipher Feedback (CFB)
  • Counter (CTR)
  • Output Feedback (OFB)
  • Retail MAC (ISO/IEC 9797-1 Algorithm 3)

Features

  • Provides simple and modern API
  • Most of the APIs are strictly typed
  • Fully complies with FIPS 46-3 standard
  • Supports Bun, Node.js, Deno, Browsers

Examples

ECB mode

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

const key = Buffer.from("1122334455667788", "hex");
const plaintext = Buffer.from("11223344556677881122334455667788", "hex");
const encrypted = encryptECB(key, plaintext);
console.log(encrypted); // Uint8Array [ ... ]

const decrypted = decryptECB(key, encrypted);
console.log(decrypted); // Uint8Array [ ... ]

ECB mode (3DES-EDE)

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

const key = Buffer.from("1122334455667788...1122334455667788", "hex");
const plaintext = Buffer.from("11223344556677881122334455667788", "hex");
const encrypted = encryptECB(key, plaintext, true);
console.log(encrypted); // Uint8Array [ ... ]

const decrypted = decryptECB(key, encrypted, true);
console.log(decrypted); // Uint8Array [ ... ]