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

Error in imports pyCrypto

My problem is the follow: I have installed pyCrypto in my computer. Then when I execute a script the intepreter say this: from: can't read /var/mail/Crypto.Cipher ./entrega2.py: line 2: syntax error near unexpected token (' ./entrega2.py: line 2:…
JomsDev
  • 116
  • 1
  • 9
0
votes
1 answer

How to make M2Crypto work with aes128-cbc-pkcs7?

In Python script I need to decrypt data encrypted by aes128-cbc-pkcs7 I checked example in Problem with M2Crypto's AES answer, but it describes aes128-cbc and I have no idea how to adopt it for aes128-cbc-pkcs7 All I have is a key: key =…
Zelid
  • 6,905
  • 11
  • 52
  • 76
0
votes
1 answer

Python Crypto RSA textbook encryption versus openssl - what is it doing?

I have an existing set of Python code that uses the primitive (textbook) RSA encryption mechanism to encrypt small pieces of data. Specifically, the python code loads a public key into variable publickey and then encrypts this data using the…
Marc
  • 3,386
  • 8
  • 44
  • 68
0
votes
2 answers

Making CryptoJS and pycrypto compatible

I'm trying to figure out how to use the CryptoJS library for AES but the documentation is somewhat scarce. I've followed their example but I can't seem to decode something that I encoded in PyCrypto I've formatted as follows: key =…
Josh
  • 107
  • 2
  • 9
0
votes
1 answer

pycrypto AES passphrase greater than block size

I have a quick question with reference to pycrypto AES encryption. Suppose I use the accepted answer to the Encrypt & Decrypt using PyCrypto AES 256, and I have my passphrase to AES encryptor > 16 bytes(my block size), will the data be truncated or…
kate
  • 113
  • 1
  • 5
  • 17
0
votes
1 answer

Pycrypto AES encrypted data has strange symbols (python)

A novice programmer here trying to encrypt a data string using pycrypto AES. After careful analysis and trying it out in python shell, I have coded crypt.py and tried running it. The AES function which was running perfectly in the shell started…
kate
  • 113
  • 1
  • 5
  • 17
0
votes
1 answer

Not able to install python module pycrypto

I am trying to use a python module for using Mega and it requires me to have pycrypto installed. I tried using both pip and easy_install to install it but I have had no luck. With pip I am getting an error like this post. I followed the link from…
bs7280
  • 1,074
  • 3
  • 18
  • 32
0
votes
1 answer

PyCrypto Decrypting Cipher text does no yield plaintext

I was playing around PyCrypto's AES and DES implementation. Every time, I decrypted a cipher text, that I encrypted from a plain text, It gives out random strings. I have tried the following: from Crypto.Cipher import AES,DES from Crypto import…
tmj
  • 1,750
  • 2
  • 19
  • 34
0
votes
1 answer

Installation issue pycrypto-2.6 on Windows 8

Not sure what I'm doing wrong but when I run pycrypto-2.6.win-amd64-py3.3.exe I get Python 3.3 is required, which I have just installed before I tried to install the crypto. I should also note that I have VS 2013 installed, as I'm reading that I may…
Risho
  • 2,561
  • 5
  • 31
  • 56
0
votes
1 answer

Why is decryption failing after separate writes to this file-like object?

I'm working on a toy module to encrypt tempfiles. The idea is to expose an interface similar to that found in the tempfile module, but to have data transparently encrypted using session keys. Again, it's just a toy project and not production…
Louis Thibault
  • 20,240
  • 25
  • 83
  • 152
0
votes
1 answer

installing pycrypto on mountain lion with xcode 5

I can't install pycrypto on mountain lion. I have command line tools installed (done from xcode 5) When I type in pip install pycrypto: .../.../ build/pycrypto': configure: error: C compiler cannot create executables I've tried to symlink gcc as…
user798719
  • 9,619
  • 25
  • 84
  • 123
0
votes
1 answer

Unknown Error in AES CBC encryption pycrypto 2.6

Unknown Error in pycrypto AES CBC encryption, The key is stripped to 16bytes but still it gives this error: Source Help Article: http://support.ideascale.com/kb/ideascale-setup/single-sign-on-multipass-token-based Update Class module: class…
sandeep koduri
  • 500
  • 2
  • 15
0
votes
3 answers

Python RSA encrypt integers

I am trying to encrypt an integer using RSA. I observed that I can encrypt a string but cannot encrypt an Integer. here are the relevant code snippets: Could not encrypt the integer, 4: crypto:~$ python Python 2.7.3 (default, Aug 1 2012, 05:14:39)…
Neon Flash
  • 3,113
  • 12
  • 58
  • 96
0
votes
1 answer

What is the encoding of ciphers in PyCrypto? Need to send to a JS client to decrypt

Using PyCrypto RSA import base64 from Crypto.PublicKey import RSA key = RSA.importKey(open('./keyBR.pub', 'r').read()) privkey = RSA.importKey(open('./privkeyBR.pem', 'r').read()) >>> message = "This is the story" >>> ciphertext = key.encrypt(…
unixsnob
  • 1,685
  • 2
  • 19
  • 45
0
votes
2 answers

different encrypted versions on encrypting the same string using the same key

This is simply driving me crazy. This is what happenned: Inside the python shell: >>> from Crypto.Cipher import ARC4 >>> a = ARC4.new('0123456789123456') >>> b = ARC4.new('0123456789123456') >>> de = b.decrypt >>> en = a.encrypt >>>…
IcyFlame
  • 5,059
  • 21
  • 50
  • 74