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
7
votes
1 answer

AES Encryption in PowerShell and Python

My goal is to be able to AES encrypt a string in PowerShell, send it to a UNIX system with python available, and decrypt the string back to plain text. I would also like to be able to do the inverse. I am not a crypto guy or a PowerShell/python…
7
votes
1 answer

Compile Python debug and pip install debug libraries

I am trying to debug some mysterious crashes in my PySide application. I am currently on Python 2.7 in Windows and want to build the debug versions of Python and PySide to help debug. I followed the instructions here to build the debug version of…
o.c.
  • 271
  • 1
  • 3
  • 12
7
votes
4 answers

pycrypto installation: configure error: cannot run C compiled programs

Please be gentle on me. I have searched the site, and I know there is another answer to this exact question, but the answers posted there aren't working for me. I am trying to install pycrypto, so that I can get paramiko to work. Paramiko is…
user1858261
  • 71
  • 1
  • 3
7
votes
2 answers

How to use encrypted RSA private key with PyCrypto?

I am generating a key with OpenSSL, providing the password from stdin: openssl genpkey -algorithm RSA -out private-key.pem -outform PEM -pass stdin -des3 -pkeyopt rsa_keygen_bits:4096 The key then looks like: -----BEGIN ENCRYPTED PRIVATE…
stf
  • 591
  • 1
  • 4
  • 19
7
votes
3 answers

How to add a padding to the data to make it acceptable for AES256 encryption algorithm in pycrypto library

Can someone tell me how to add a padding to the data to make it acceptable for AES256 encryption algorithm in pycrypto library (Python). Thanks a lot in advance.. :)
Rise
  • 820
  • 4
  • 18
  • 33
7
votes
1 answer

PyCrypto on Google App Engine (1.7.0) with Python 2.7 on Mac OS X 10.8 causes ImportError

I am trying to get PyCrypto working with Google App Engine, and I have a lengthy description of an issue I have encountered that is reported as issue 7925 for Google App Engine. Essentially, I do not know of a sensible way to install PyCrypto on Mac…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
6
votes
1 answer

Include nonce and block count in PyCrypto AES MODE_CTR

Some background information, you can skip this part for the actual question this is my third question about this topic here at stackoverflow. To be complete, these are the other questions AES with crypt-js and PyCrypto and Match AES de/encryption in…
samuirai
  • 762
  • 1
  • 9
  • 25
6
votes
2 answers

How to install Pycrypto for Python 3.7.2?

When installing Pycrypto, a compiler error occurs I need to install Pycrypto thrue pip install C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc/…
Ben_r007
  • 69
  • 1
  • 1
  • 3
6
votes
1 answer

Pycrypto : AES Decryption

Why Pycrypto AES decryption gives different output when decrypted with AES object used for encryption and right output when decrypted with AES object used solely for decryption? from Crypto.Cipher import AES obj = AES.new('0123456789012345',…
Pankhuri Agarwal
  • 764
  • 3
  • 23
6
votes
1 answer

Image encryption and decryption using Pycrypto

How can I encrypt images using the Pycrypto python library? I found some text encrypting examples on internet, but I didn't find the same with images. Can anyone help me?
user7500581
6
votes
1 answer

Generating Large Prime Numbers with Py Crypto

I'm trying to generate a large prime number (2048 bits) using the crypto library in python in order to implement RSA. However, I do not really understand the syntax of the getPrime() function. I currently have: from Crypto.Util import…
winsticknova
  • 365
  • 2
  • 5
  • 17
6
votes
2 answers

Python Crypto, RSA Public/Private key, with large file

I now know that RSA Public/Private key can only encrypt very short input at once, but can anyone provide a way to encrypt any type of file(.txt, .phf, .exe, etc) with only the public/private key? I do not want to have additional AES key. Here is my…
Jack Feng
  • 895
  • 2
  • 9
  • 24
6
votes
1 answer

AES_128_CTR encryption by openssl and PyCrypto

Wondering the right way to convert a AES_128_CTR encryption by openssl to PyCrypto. First, I did an encryption by openssl as following: openssl enc -aes-128-ctr -in input.mp4 -out output.openssl.mp4 -K 7842f0a1ebc38f44e3e0c81943f68582 -iv…
Drake Guan
  • 14,514
  • 15
  • 67
  • 94
6
votes
1 answer

How can you store a rsa key pair in a django model / sqlite db

i am using PyCrypto within Django (Python 2.7, Django 1.5m SQLite), i would like to create a field to store an RSAkey object. How can i do this? Converting to a string and back seems pretty error prone and since random bytes are in there, i would…
Fluffy
  • 75
  • 1
  • 6
6
votes
1 answer

Building PyCrypto with fastmath (gmp or mpir) via pip on Windows

I installed PyCrypto on Windows via pip but i was not able to build Crypto.PublicKey._fastmath because GMP was not found. I know there is a binary version on voidspace but i would like to build the latest version of PyCrypto
scherlock
  • 217
  • 3
  • 8