Web Analytics

blowfish

⭐ 54 stars Simplified Chinese by egoroof

Blowfish

[![npm package][npm-badge]][npm]

[npm-badge]: https://img.shields.io/npm/v/egoroof-blowfish.svg?style=flat-square [npm]: https://www.npmjs.com/package/egoroof-blowfish

Blowfish>) 加密库,适用于浏览器和 Node.js。

CHANGELOG.md 中查看更新日志

目录

安装

获取最新版本 这里 或使用 npm:

npm install egoroof-blowfish --save

JS 模块

该库仅以原生 JS 模块形式部署,因此在浏览器中必须使用 type 为 modulescript

或者将库打包到你的代码中。

在 Nodejs 中它可以轻松导入:

import { Blowfish } from 'egoroof-blowfish';

用法

所有输入数据包括密钥、IV、明文和密文应为 StringArrayBuffer / Buffer。 字符串支持所有unicode字符,包括表情符号 ✨。

示例

import { Blowfish } from 'egoroof-blowfish';

const bf = new Blowfish('super key', Blowfish.MODE.ECB, Blowfish.PADDING.NULL); // only key isn't optional bf.setIv('abcdefgh'); // optional for ECB mode; bytes length should be equal 8

const encoded = bf.encode('input text even with emoji 🎅'); const decoded = bf.decode(encoded, Blowfish.TYPE.STRING); // type is optional

Block cipher mode of operation

https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation

Blowfish.MODE.ECB; // (default) Electronic Codebook
Blowfish.MODE.CBC; // Cipher Block Chaining

Padding

http://www.di-mgt.com.au/cryptopad.html

Blowfish.PADDING.PKCS5; // (default) Pad with bytes all of the same value as the number of padding bytes
Blowfish.PADDING.ONE_AND_ZEROS; // Pad with 0x80 followed by zero bytes
Blowfish.PADDING.LAST_BYTE; // Pad with zeroes except make the last byte equal to the number of padding bytes
Blowfish.PADDING.NULL; // Pad with zero (null) characters
Blowfish.PADDING.SPACES; // Pad with spaces

返回类型

方法 decode 应返回哪种类型的数据:

Blowfish.TYPE.STRING; // (default) String
Blowfish.TYPE.UINT8_ARRAY; // Uint8Array

--- Tranlated By Open Ai Tx | Last indexed: 2026-07-13 ---