File: README

package info (click to toggle)
python-crypto 2.6.1-7
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,032 kB
  • ctags: 3,599
  • sloc: ansic: 12,466; python: 10,482; sh: 41; makefile: 14
file content (103 lines) | stat: -rw-r--r-- 4,118 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Python Cryptography Toolkit (pycrypto)
======================================

This is a collection of both secure hash functions (such as SHA256 and
RIPEMD160), and various encryption algorithms (AES, DES, RSA, ElGamal,
etc.).  The package is structured to make adding new modules easy.
This section is essentially complete, and the software interface will
almost certainly not change in an incompatible way in the future; all
that remains to be done is to fix any bugs that show up.  If you
encounter a bug, please report it in the Launchpad bug tracker at

       https://launchpad.net/products/pycrypto/+bugs

An example usage of the SHA256 module is:
>>> from Crypto.Hash import SHA256
>>> hash = SHA256.new()
>>> hash.update('message')
>>> hash.digest()
'\xabS\n\x13\xe4Y\x14\x98+y\xf9\xb7\xe3\xfb\xa9\x94\xcf\xd1\xf3\xfb"\xf7\x1c\xea\x1a\xfb\xf0+F\x0cm\x1d'

An example usage of an encryption algorithm (AES, in this case) is:

>>> 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'

One possible application of the modules is writing secure
administration tools.  Another application is in writing daemons and
servers.  Clients and servers can encrypt the data being exchanged and
mutually authenticate themselves; daemons can encrypt private data for
added security.  Python also provides a pleasant framework for
prototyping and experimentation with cryptographic algorithms; thanks
to its arbitrary-length integers, public key algorithms are easily
implemented.

As of PyCrypto 2.1.0, PyCrypto provides an easy-to-use random number
generator:

>>> from Crypto import Random
>>> rndfile = Random.new()
>>> rndfile.read(16)
'\xf7.\x838{\x85\xa0\xd3>#}\xc6\xc2jJU'

A stronger version of Python's standard "random" module is also
provided:

>>> from Crypto.Random import random
>>> random.choice(['dogs', 'cats', 'bears'])
'bears'

Caveat: For the random number generator to work correctly, you must
call Random.atfork() in both the parent and child processes after
using os.fork()


Installation
============

PyCrypto is written and tested using Python version 2.1 through 3.2.  Python
1.5.2 is not supported.

The modules are packaged using the Distutils, so you can simply run
"python setup.py build" to build the package, and "python setup.py
install" to install it.

If the setup.py script crashes with a DistutilsPlatformError
complaining that the file /usr/lib/python2.2/config/Makefile doesn't
exist, this means that the files needed for compiling new Python
modules aren't installed on your system.  Red Hat users often run into
this because they don't have the python2-devel RPM installed.  The fix
is to simply install the requisite RPM.  On Debian/Ubuntu, you need the
python-dev package.

To verify that everything is in order, run "python setup.py test".  It
will test all the cryptographic modules, skipping ones that aren't
available.  If the test script reports an error on your machine,
please report the bug using the bug tracker (URL given above).  If
possible, track down the bug and include a patch that fixes it,
provided that you are able to meet the eligibility requirements at
http://www.pycrypto.org/submission-requirements/.

It is possible to test a single sub-package or a single module only, for instance
when you investigate why certain tests fail and don't want to run the whole
suite each time. Use "python setup.py test --module=name", where 'name'
is either a sub-package (Cipher, PublicKey, etc) or a module (Cipher.DES,
PublicKey.RSA, etc).
To further cut test coverage, pass also the option "--skip-slow-tests".

To install the package under the site-packages directory of
your Python installation, run "python setup.py install".

If you have any comments, corrections, or improvements for this
package, please report them to our mailing list, accessible via the
PyCrypto website:

    http://www.pycrypto.org/