1.0.6 • Published 2 years ago

@kaffee/espresso v1.0.6

Weekly downloads
-
License
GPLV3
Repository
github
Last release
2 years ago

@kaffee/espresso

A based TypeScript crypto library, tree shaking support

Installation

Install with npm

  npm install --dev @kaffee/espresso

Install with yarn

  yarn add --dev @kaffee/espresso

Install with pnpm

  pnpm add -D @kaffee/espresso

Support List

Hash

  • md4
  • md5
  • pbkdf2
  • ripemd128
  • ripemd160
  • ripemd256
  • ripemd320
  • sha1
  • sha3
  • sha224
  • sha256
  • sha384
  • sha512

Hmac Hash

  • md4
  • md5
  • pbkdf2
  • ripemd128
  • ripemd160
  • ripemd256
  • ripemd320
  • sha1
  • sha3
  • sha224
  • sha256
  • sha384
  • sha512

Block Cipher

  • AES
  • DES
  • Triple DES

Stream Cipher

but is not support

  • SEED
  • Rabbit
  • Rabbit Legacy
  • RC4

Example

Hash Example

import { MD5 } from "@kaffee/espresso";

const hash = MD5("LIBAOBAO").toString();

Block Cipher Example

import { AES, enc, RIPEMD160, mode, pad } from "@kaffee/espresso";

function AESEncrypt(text: string, keyStr: string, ivStr: string): string {
  const key = RIPEMD160(keyStr).toString().slice(0, 16);
  const iv = enc.Utf8.parse(ivStr);
  return AES.encrypt(text, Utf8.parse(key), {
    iv,
    mode: mode.CBC,
    padding: pad.PKCS7
  }).toString();
}

function AESDecrypt(text: string, key: string, ivStr: string): string {
  const iv = enc.Utf8.parse(ivStr);
  return AES.decrypt(text, key, {
    iv,
    mode: mode.CBC,
    padding: pad.PKCS7
  }).toString(enc.Utf8);
}

Other

tree shaking

License

GPL

Contributors