| 1 |
Blowfish |
| 2 |
======== |
| 3 |
|
| 4 |
.. warning:: |
| 5 |
Use :doc:`aes`. This module is provided only for legacy purposes. |
| 6 |
|
| 7 |
Blowfish_ is a symmetric block cipher designed by Bruce Schneier. |
| 8 |
|
| 9 |
It has a fixed data block size of 8 bytes and its keys can vary in length |
| 10 |
from 32 to 448 bits (4 to 56 bytes). |
| 11 |
|
| 12 |
Blowfish is deemed secure and it is fast. However, its keys should be chosen |
| 13 |
to be big enough to withstand a brute force attack (e.g. at least 16 bytes). |
| 14 |
|
| 15 |
As an example, encryption can be done as follows:: |
| 16 |
|
| 17 |
>>> from Crypto.Cipher import Blowfish |
| 18 |
>>> from struct import pack |
| 19 |
>>> |
| 20 |
>>> bs = Blowfish.block_size |
| 21 |
>>> key = b'An arbitrarily long key' |
| 22 |
>>> cipher = Blowfish.new(key, Blowfish.MODE_CBC) |
| 23 |
>>> plaintext = b'docendo discimus ' |
| 24 |
>>> plen = bs - len(plaintext) % bs |
| 25 |
>>> padding = [plen]*plen |
| 26 |
>>> padding = pack('b'*plen, *padding) |
| 27 |
>>> msg = cipher.iv + cipher.encrypt(plaintext + padding) |
| 28 |
|
| 29 |
.. _Blowfish: http://www.schneier.com/blowfish.html |
| 30 |
|
| 31 |
.. automodule:: Crypto.Cipher.Blowfish |
| 32 |
:members: |