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'
889 questions
0
votes
1 answer

PyCrypto: text to decrypt must be a multiple of 16-bytes long

I've tried to do a encryptor program with PyCrypto... It works but some times when I decrypt I give me the error that the text to decrypt must be a multiple of 16-bytes long. Don't watch the "print" because the language is Italian. from…
iampirla
  • 35
  • 1
  • 1
  • 11
0
votes
1 answer

Install pycrypto on Mac OS X without gcc

I'm trying to install pycrypto because it's one of the dependencies for ansible. I know that gcc can be installed on Mac by installing Xcode Command Line Tools but I don't want to install Xcode because its installation can't be automated. (I need to…
rhee
  • 87
  • 3
  • 8
0
votes
1 answer

Is there any way to export a public key from pycrypto with a rfc4716 subject or comment header?

I'm using pycypto but I don't mind using any library. http://www.ietf.org/rfc/rfc4716.txt I'd like to export a public key with a subject or comment header as defined in rfc4716 but I can't seem to see any functionality to do so.
Duke Dougal
  • 24,359
  • 31
  • 91
  • 123
0
votes
1 answer

Migrating RSA signature generation from m2crypto to pycrypto

I am hoping you can help me out with my migration to PyCrypto from M2Crypto. The content to encrypt is XML. I am loading the pk as follows: M2Crypto: sha = hashlib.sha1(xml) rsa_private_key = M2Crypto.RSA.load_key_string(PRIVATE_KEY) signature =…
0
votes
1 answer

Python 3 - Socket Chat Encryption with PyCrypto gives UnicodeDecodeError

I am trying to setup a socket chat with encryption in Python 3, but when decoding UTF-8 it gives an error. Here is the code: Client: from Crypto.Cipher import AES from Crypto import Random import socket, sys host = 'localhost' port = 5558 IV =…
user4884072
  • 81
  • 3
  • 10
0
votes
1 answer

Passing encrypted data between Python Gae and Client

I am trying to learn how to pass encrypted data between server (Python gae) and client(jquery) The following sketch of a code fragment at the server works: random_generator = Random.new().read key = RSA.generate(1024,random_generator) publicKey …
0
votes
1 answer

Installing pycrypto on raspbian for python 3.2.3

Im trying to crate a cryptosystem on the raspbian OS. Chose python and pycrypto because the OS comes with python 3.2.3 pre-installed. Moved the "pycrypto-2.6.1.tar.gz" to the folder where python files are located and extracted there. Suposed to…
0
votes
1 answer

Length of output of AES 128 encryption in python

When I am trying to convert to hex the output of my AES 128 encryption code using pycrypto. I am using hexlify .the output is 64 bits for a 32 bits input. The output is always double the size for any input and when use an online compiler I get a…
Sid
0
votes
2 answers

Problems retrieving stored AES encrypted string in Python

I am having a problem storing a string encrypted, then b64 encoded in a text file. The code to encrypt is from base64 import b64encode, b64decode # import library for B64 from Crypto.Cipher import AES import datetime d =…
PaulP
  • 48
  • 6
0
votes
1 answer

ImportError: No module named 'Crypto' is occuring after installing packages also

After installing simpleCrypto and PyCrypto in windows... i am getting this error... steps followed: cd simplecryto/dist; python setup.py install cd pycrypto/dist; python setup.py install test.py: from simplecrypt import encrypt, decrypt ciphertext…
0
votes
0 answers

How to install the third-party python (2.7) modules (e.g. Pycrypto) on ARM?

I have compiled and installed Python-2.7.9 on my ARM-based device. When I try to install the Pycrypto, there comes the problems as follows. First, I downloaded the source code, did python setup.py install, but it went wrong by telling the the…
Julian
  • 21
  • 3
0
votes
1 answer

Using Crypto by placing folder in python path? - Python

I'm using Django in order to serve a web service. I have only access to FTP and code refresh at the moment. No access to command-line or executing any kind of executable. I am using a Windows Server 2005 machine. Would I be able to use Crypto just…
RadiantHex
  • 24,907
  • 47
  • 148
  • 244
0
votes
0 answers

Having issues with a corrupt encryption error

Im trying to encrypt every line of the file test.txt the function encrypt() will output basically the text all jumbled up. For an end of year project in my computer science class. But my problem is when i try to run the code "backwards" with…
0
votes
0 answers

How to install pycrypto _fastmath.so in the correct place

My question is how can I configure the installation of pycrypto so _fastmath gets put into the correct place. I have followed the instructions in this excellent SO post. However, I cannot get past this error and need some…
octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
0
votes
1 answer

How to import PyCrypto inside App Engine development server (OS X)?

My app.yaml include this lines: libraries: - name: pycrypto version: "2.6" I have the correct version of PyCrypto: $ python >>> import Crypto >>> Crypto.__version__ '2.6' But when I try evaluate import Crypto in GAE Development SDK interactive…
defuz
  • 26,721
  • 10
  • 38
  • 60