Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 1023 Bytes

blowfish.rst

File metadata and controls

32 lines (24 loc) · 1023 Bytes

Blowfish

Warning

Use aes. This module is provided only for legacy purposes.

Blowfish is a symmetric block cipher designed by Bruce Schneier.

It has a fixed data block size of 8 bytes and its keys can vary in length from 32 to 448 bits (4 to 56 bytes).

Blowfish is deemed secure and it is fast. However, its keys should be chosen to be big enough to withstand a brute force attack (e.g. at least 16 bytes).

As an example, encryption can be done as follows:

>>> from Crypto.Cipher import Blowfish
>>> from struct import pack
>>>
>>> bs = Blowfish.block_size
>>> key = b'An arbitrarily long key'
>>> cipher = Blowfish.new(key, Blowfish.MODE_CBC)
>>> plaintext = b'docendo discimus '
>>> plen = bs - len(plaintext) % bs
>>> padding = [plen]*plen
>>> padding = pack('b'*plen, *padding)
>>> msg = cipher.iv + cipher.encrypt(plaintext + padding)

Crypto.Cipher.Blowfish