Questions tagged [pycrypto]

PyCrypto - The Python Cryptography Toolkit is a package that contains various cryptographic modules for the Python programming language.

Warning: PyCrypto seems not maintained anymore

It seems that the PyCrypto project has not been maintained since 2014. The developers are not doing any activity on the official repository during these years and they are not providing support about issues. This is why this post suggests to replace it with the PyCryptodome library, which still creates a Crypto package with an almost identical API and can be used with most software, although there are some exceptions. For more details about compatibility between these two packages visit this page.

About PyCrypto

From the PyCrypto PyPi page:

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.

And from the PyCrypto GitHub repository:

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.

Official resources

Installation

As the PyCrypto PyPi page suggests, an easy way to install PyCrypto is by using the following command.

pip install pycrypto

Examples

From the PyCrypto GitHub repository:

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 key123', AES.MODE_CBC, 'This is an IV456')
>>> message = "The answer is no"
>>> ciphertext = obj.encrypt(message)
>>> ciphertext
'\xd6\x83\x8dd!VT\x92\xaa`A\x05\xe0\x9b\x8b\xf1'
>>> obj2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
>>> obj2.decrypt(ciphertext)
'The answer is no'
845 questions
26
votes
1 answer

How to set CFLAGS and LDFLAGS to compile pycrypto

I am trying to install the fabric library to an old machine. There are some legacy libraries in /usr/lib, such as libgmp. (py27)[qrtt1@hcservice app]$ ls /usr/lib|grep…
qrtt1
  • 7,276
  • 8
  • 37
  • 56
26
votes
5 answers

PyCrypto on python 3.5

I found some PyCrypto installers for Python 3.3 and 3.4, but nothing for Python 3.5. When I try to install PyCrypton using pip install, it says: warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. Is there any way…
Trsak
  • 293
  • 1
  • 4
  • 8
23
votes
3 answers

Signing and verifying data using pycrypto (RSA)

I am trying to familiarize myself with the pycrypto module, but the lack of clear documentation makes things difficult. To start with, I would like to understand signing and verifying data. Could someone please provide an example for how this would…
Noah McIlraith
  • 12,932
  • 7
  • 24
  • 35
21
votes
8 answers

How do I create a user and set a password using ansible?

The documentation refers us to the github example, but this is a bit sparse and mysterious. It says this: # created with: # crypt.crypt('This is my Password', '$1$SomeSalt') password: $1$SomeSalt$UqddPX3r4kH3UL5jq5/ZI. but crypt.crypt doesn't emit…
Chris Sattinger
  • 3,788
  • 3
  • 26
  • 27
21
votes
2 answers

How do I use a X509 certificate with PyCrypto?

I want to encrypt some data in python with PyCrypto. However I get an error when using key = RSA.importKey(pubkey): RSA key format is not supported The key was generated with: openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.key…
eshizhan
  • 3,177
  • 2
  • 16
  • 18
19
votes
4 answers

Failed installing pycrypto with pip

I encountered a problem when I try to download a certain package: C:\Python27\Scripts>pip install pycrypto Collecting pycrypto Using cached…
S. Backlayn
  • 777
  • 1
  • 6
  • 11
19
votes
2 answers

AES - Encryption with Crypto (node-js) / decryption with Pycrypto (python)

I'm writing this question + answer because I struggled a lot (maybe because of a lack of experience), got lost in many different ways of encrypting/decrypting things with node or python. I thought maybe my case could help people in the future. What…
nnaelle
  • 892
  • 1
  • 7
  • 22
18
votes
5 answers

LINK : fatal error LNK1104: cannot open file 'python27.lib'

I was trying to compile pycrypto-2.6.1 from source for Python 2.7.10 64-Bit Windows Version and facing the following error. Processing pycrypto-2.6.1.tar.gz Writing…
Sivasubramaniam Arunachalam
  • 6,984
  • 15
  • 71
  • 126
18
votes
4 answers

ImportError: No module named Crypto

I am just starting to explore Python. I am trying to run an AES algorithm code and I am facing the: ImportError: No module named Crypto. How do you solve this?
AK1992
  • 201
  • 1
  • 2
  • 5
18
votes
14 answers

Trying to install pycrypto on Mac OSX mavericks

I am currently trying to install pycrypto and when I execute python setup.py build I receive this following error: cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.9-intel-2.7/src/_fastmath.o -lgmp -o…
user1798733
17
votes
3 answers

Saving RSA keys to a file, using pycrypto

I’m using PyCrypto 2.3 and I would like to save the keys I have generated into a file, so as to distribute them to the client and server. I can’t seem to find a way to print the keys correctly, neither can I find examples on the internet. def…
qdii
  • 11,387
  • 7
  • 54
  • 107
17
votes
1 answer

Using RSA in Python

I am using RSA to encrypt/decrypt my session keys in Python. I am using Pycrypto library. After generating the keypair, I want to extract the private key and public key from that generated key and store them in different files. How can I do this? I…
Tara Singh
  • 1,701
  • 5
  • 24
  • 34
17
votes
5 answers

How can I create an encrypted django field that converts data when it's retrieved from the database?

I have a custom EncryptedCharField, which I want to basically appear as a CharField when interfacing UI, but before storing/retrieving in the DB it encrypts/decrypts it. The custom fields documentation says to: add __metaclass__ =…
Oved D
  • 6,244
  • 8
  • 43
  • 65
16
votes
1 answer

Can't install python module "pycrypto" on Debian lenny

I tried to install pycrypto module by downloading the source code and executing the following command python setup.py install, then an error came running install running build running build_py running build_ext warning: GMP library not found; Not…
alex CSD
  • 385
  • 2
  • 3
  • 11
16
votes
9 answers

Cryptography tools for python 3

I'm writing a program in python 3 which needs encryption functions (at least aes and rsa). I've found PyCrypto which seems to work only on 2.x versions. Is there any good tool available for python 3 or should I rather start translating my program to…
Martin Trigaux
  • 5,091
  • 9
  • 39
  • 58
1
2
3
56 57