This library implements the Blowfish symmetric-key block cipher for JavaScript, supporting both browser and Node.js environments. Currently at version 1.0.4, the package provides basic encryption and decryption capabilities, including Electronic Codebook (ECB) and Cipher Block Chaining (CBC) modes. A key feature is its robust handling of UTF-8 strings and automatic zero-padding to ensure input data conforms to Blowfish's 8-byte block length, with a utility to `trimZeroes` after decryption for text. It also offers built-in base64 encoding/decoding for handling the binary output of encryption. While Blowfish was designed for speed and flexibility with variable key lengths (32-448 bits) in 1993, its 64-bit block size is now considered a security weakness due to susceptibility to 'Sweet32' birthday attacks, especially for large data volumes (over 4GB). It's generally recommended for legacy systems or specific constrained environments rather than new applications, where modern ciphers like AES or Twofish are preferred. The library itself appears to be in a maintenance or inactive state, with no recent updates since 2018.
npm install javascript-blowfishVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic Blowfish encryption and decryption using a secret key. It covers handling the binary output of encryption, including trimming zero padding for text data and using base64 encoding for convenient representation.
For new applications or large data volumes, prefer modern ciphers like AES (e.g., `crypto` module in Node.js) or Twofish, which use larger block sizes (e.g., 128-bit).
Always use `bf.base64Encode()` on the encrypted output before storing or transmitting it, and `bf.base64Decode()` before decryption, as shown in the examples. This converts the binary data into a safe text format.
After decrypting text data, explicitly call `bf.trimZeroes(decryptedString)` to remove the trailing null characters and restore the original plaintext.
Ensure you provide an 8-byte string as the second argument to `bf.encrypt(message, 'cbcvecto')` and `bf.decrypt(encrypted, 'cbcvecto')` when operating in CBC mode. The IV should be unique for each encryption operation (though not necessarily secret) and transmitted alongside the ciphertext.
Consider migrating to Advanced Encryption Standard (AES) implementations (e.g., Node.js's built-in `crypto` module or a well-vetted third-party library) for new projects to ensure better security posture and performance on modern hardware.
For text data, apply `bf.trimZeroes(decryptedString)` after decryption to remove the padding characters.
Pass an 8-byte string as the second argument to the `Blowfish` constructor if specifying 'cbc' mode, and also to the `encrypt` and `decrypt` methods. E.g., `new Blowfish("key", "cbc"); bf.encrypt("message", "cbcvecto");`Use `bf.base64Encode()` on the result of `bf.encrypt()` to convert the binary string into a safe, ASCII-representable format. Remember to `bf.base64Decode()` it before decryption.
No dependency data recorded yet.