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

How to reverse hash string, using python

I have hashed email Ids and I want to implement some process so that I can reverse hash string. I just tried this approach using python hashlib and pycrypto modules, but unfortunately I failed , and also I read many posts on the same topic but none…
Amrish Mishra
  • 100
  • 1
  • 12
-2
votes
1 answer

Where to find PEM file created using pycrypto

I want to know where I can find exported keys. I don't see .pem file in my current directory. I am able to save key to txt file but its not working when I am trying to encrypt string using that key. Please help from Crypto import Random from…
amol rane
  • 173
  • 10
-2
votes
1 answer

I tried to download PyCrypto for Python 3.7 but failed

I ran command prompt as administrator then typed pip install pycrypto and got this error message: Command ""c:\program files (x86)\python37-32\python.exe" -u -c "import setuptools, …
Strinix
  • 3
  • 2
-2
votes
1 answer

xoring bytes and str (AES CBC)

Hi I would really appreciate the help on this one since i'm really lost and I don't get why it's not working. I have a 16 byte key and 16 byte block but the key type is 'str' and the block type is 'bytes' and I want to xor between them but the value…
LiorA
  • 432
  • 3
  • 12
-4
votes
1 answer

Pyinstaller doesn't find crypto. (even in hidden import)

I word with windows 10, python 3.7. (i am also a linux user and to be honest i don't try this with fedora should i try ?) I use the lastest version of pyinstaller. When i execute the .exe "ModuleNotFoundError: No module named 'Crypto'" I double…
1 2 3
56
57