Blowfish keys must be at least 128 bits longJAVA-S1015
The Blowfish cipher supports key sizes from 32 bits to 448 bits. A small key size makes the ciphertext vulnerable to brute force attacks.
At least 128 bits of entropy should be used when generating Blowfish keys.
The blowfish cipher is a reliable symmetric block-based encryption algorithm with good performance and security for plaintext smaller than 4 Gigabytes in size. This size limitation stems from the smaller block size (64 bits), with larger plain-texts suffering from the possibility of a birthday attack reducing the cipher's security. At lower-key sizes, the security of the blowfish cipher degrades due to the increased chance of a brute force attack succeeding.
It is thus recommended that the key be at minimum 128 bits long.
Bad Practice
KeyGenerator kg = KeyGenerator.getInstance("Blowfish");
kg.initialize(64); // Insecure.
Recommended
Always use a key size of at least 2048 bits to ensure proper security of your application.
KeyGenerator kg = KeyGenerator.getInstance("Blowfish");
kg.initialize(128);
References
- FindSecBugs - BLOWFISH_KEY_SIZE
- Wikipedia entry on Blowfish
- NIST - Latest publication on key management
- CWE-326 - Inadequate Encryption Strength
- OWASP Top Ten (2021) - Category A05 - Security Misconfiguration
- OWASP Top Ten (2021) - Category A02 - Cryptographic Failures