Python Cryptography Toolkit

Installation

Download:

wget http://www.amk.ca/files/python/crypto/pycrypto-2.0.1.tar.gz

Decompress:

gunzip pycrypto-2.0.1.tar.gz
tar -xf pycrypto-2.0.1.tar

Installation:

cd pycrypto-2.0.1
python setup.py install

Using

Some good examples are in README file.

In Python:

Import module:

from Crypto.Cipher import AES
>>> obj=AES.new('This is a key456', AES.MODE_ECB)
>>> message="The answer is no"
>>> ciphertext=obj.encrypt(message)
>>> ciphertext
'o\x1aq_{P+\xd0\x07\xce\x89\xd1=M\x989'
>>> obj2 = AES.new('This is a key456', AES.MODE_ECB)
>>> obj2.decrypt(ciphertext)
'The answer is no'

Cypher inicialization:

password = 'This is a key456'
cipher = AES.new(password, AES.MODE_ECB)
  • Length of key 1) must have 16, 24 or 32 characters.

Encryption:

plaintext = "The answer is no"
ciphertext = cipher.encrypt(plaintext)
  • Length of plaintext must have 16, 24 or 32 characters.
>>> ciphertext
'o\x1aq_{P+\xd0\x07\xce\x89\xd1=M\x989'

Decryption:

password = 'This is a key456'
cipher2 = AES.new(password, AES.MODE_ECB)
plaintext = cipher2.decrypt(ciphertext)
>>> plaintext
'This is a key456'

Enjoy …

…matus…

1) password
 
python_cryptography_toolkit.txt · Last modified: 31.03.2010 17:51 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki