A based TypeScript crypto library, tree shaking support
Install with npm
npm install --dev @kaffee/espresso
Install with yarn
yarn add --dev @kaffee/espresso
Install with pnpm
pnpm add -D @kaffee/espresso
- md4
- md5
- pbkdf2
- ripemd128
- ripemd160
- ripemd256
- ripemd320
- sha1
- sha3
- sha224
- sha256
- sha384
- sha512
- md4
- md5
- pbkdf2
- ripemd128
- ripemd160
- ripemd256
- ripemd320
- sha1
- sha3
- sha224
- sha256
- sha384
- sha512
- AES
- DES
- Triple DES
but is not support
- SEED
- Rabbit
- Rabbit Legacy
- RC4
import { MD5 } from "@kaffee/espresso";
const hash = MD5("LIBAOBAO").toString();
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);
}