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
2 answers

PyCrypto script producing wrong MD2 hashes

I am trying to calculate MD2 hashes using PyCrypto until i find one or more starting with a given string. (Please don't ask why :=) I am able to find several hashes. If i check the correctness of my hash calculation via online tools, i will not…
2bNs
  • 3
  • 1
0
votes
2 answers

"TypeError: Incorrect padding" in pycrypto-2.6.1(python 2.7.6) ubuntu14.04 LTS

I'm trying to make a simple public-private key encryption algorithm using pycrypto: from Crypto.PublicKey import RSA from Crypto.Signature import PKCS1_v1_5 from Crypto.Hash import SHA256 from base64 import b64encode, b64decode #Open a txt file in…
jjf
  • 115
  • 3
  • 11
0
votes
2 answers

An error when executing pycrypto

I work with odoo and I want to install the module of paybox : this one : https://bitbucket.org/anybox/anybox_paybox/ For that : this module needs pycrypto to work So, I installed pycrypto in the linux server (ubuntu) git clone…
user3854643
  • 1
  • 1
  • 3
0
votes
1 answer

Get a Public Key from Python String (SHA)

Let's say that I have a python string: string_full = """ -----BEGIN CERTIFICATE----- GIBBERISH................ ...................... ........................ -----END…
Jose_Sunstrider
  • 323
  • 1
  • 3
  • 17
0
votes
1 answer

Python pyCyrpto how to encrypt other user public key

I've got a problem. I'm using pycrypto and rsa. I want to generate my rsa keys. Then I want to send my public key (in binary or base64 or similar) but first I want to encrypt it with server public. Because I want to be sure that no one is sniffing…
Kamil
  • 35
  • 7
0
votes
1 answer

Import Public Key from GameCenter using PyCrypto on Google App Engine

I'm trying to verify a GameCenter player on a remote server using Apple's documented method: GKLocalPlayer generateIdentityVerificationSignatureWithCompletionHandler: Calling this method on iOS returns, among other things, a link to this file (this…
Shaun Budhram
  • 3,690
  • 4
  • 30
  • 41
0
votes
0 answers

PyInstaller and PyCrypto on Ubuntu

I am new in PyInstaller. I have got a program on Python and would like to convert it into stand-alone executable under Ubuntu. I try: pyinstaller -y --clean --hidden-import=Crypto.Util._counter pycrypter.py But when I execute the result file: cd…
Fomalhaut
  • 8,590
  • 8
  • 51
  • 95
0
votes
1 answer

pycrypto with multiple users in virtual environment

I'm using Paramiko (which depends on PyCrypto) on Windows in a virtual environment. Because I'm on Windows, I don't have a C compiler by default, so I got the windows executable from XXX, and installed it using: workon myenv easy_install…
Chris Curvey
  • 9,738
  • 10
  • 48
  • 70
0
votes
1 answer

cannot import name OSRNG

Trying to install third parties library in google appengine. All i want to do is install using pip then copy the folder from site-package to my project root lib folder. I did and pasted the Crypto into lib folder. then throwing below error. I wonder…
user3895077
0
votes
1 answer

AES Encryption pycrypto and salting

I don't have a problem with my code but I don't understand the different arguments you can use with pycrypto and AES encryption. so where I define my encryptor below, what is mode, and IV? the tutorial I found this on didn't really help me…
Grant Zukel
  • 1,153
  • 2
  • 24
  • 48
0
votes
1 answer

pycrypto random not supported on GAE?

I have deployed a App engine application that uses pycrypto. I installed pycrypto locally but when i deploy on the App Engine it says: TargetAppError: Traceback (most recent call last): File…
gigasai
  • 564
  • 4
  • 23
0
votes
1 answer

How to use a different version of PyCrypto in GAE Python

I downloaded the experimental version of PyCrypto (pycrypto-2.7a1.tar.gz). I have copied the "Crypto" directory (extracted from pycrypto-2.7a1.tar.gz) to my project folder. In app.yaml file: libraries: - name: pycrypto version: 2.7 # latest I…
gsinha
  • 1,165
  • 2
  • 18
  • 43
0
votes
2 answers

Running setup.py install for pycrypto 'chmod' is not recognized as an internal or external command, operable program or batch file

There is python 2.7 and already pycrypto 2.6.1 inside installed. Env Windows 8, x64. I get following error while installing requirements with pip (pip install -r file_with_requirements). Installing collected packages: pycrypto Found existing…
Jacob
  • 14,949
  • 19
  • 51
  • 74
0
votes
1 answer

Error installing pycrypto in mac 10.9.6

I am trying to install 'fabric'. I tried using 'pip install fabric' and the installation is failing when it is trying to install the 'pycrypto' I see it is fetching the 2.6.1 version. I tried installing lower versions and I am getting same…
Sharath B. Patel
  • 401
  • 1
  • 6
  • 15
0
votes
1 answer

Pycrypto fails inconsistantly to verify signature loaded from file

I am trying to have a program sign and then later verify the contents of a file. However, wile the first verification will always return true, once the data is written to files and then loaded again, the verification usually fails, but is sometimes…
Ralin
  • 13
  • 5