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

Wrong CMAC generation from Pycryptodome

As per the Example given in the documentation of PyCryptodome >>> from Crypto.Hash import CMAC >>> from Crypto.Cipher import AES >>> secret = b'Sixteen byte key' >>> cobj = CMAC.new(secret, ciphermod=AES) >>> cobj.update(b'Hello') >>> print…
NiK8
  • 19
  • 6
0
votes
1 answer

AES encryption with CBC mode in python (128-Bit keys)

I encrypted a text in AES with the code below and decrypt the Ciphertext with Online decryption websites (Website 1, Website 2). But, the decrypted text from all websites contains some unwanted strings in front as shown in this picture. import…
Hemantapkh
  • 13
  • 1
  • 6
0
votes
0 answers

Why does this program always respond with not responding message on the user interface? python code using pycrypto

So I am trying to run this program which used to work absolutely fine like 2 weeks ago and now it just shows that the user interface is not responding once I select the image and use the encrypt functionality. Last time I let it run for an hour or…
0
votes
1 answer

AES decrytion API won't accept str argument

These are the decryption functions. def decrypt(info,key): msg=info PAD="%" decipher=AES.new(new_pwd,AES.MODE_ECB) pt=decipher.decrypt(msg).decode('utf-8') # ERROR OCCURS HERE pad_index=pt.find(PAD) result=pt[:pad_index] …
user12457207
0
votes
1 answer

Convert bitcoin transaction hash to raw hexcode

I have a list of Bitcoin transaction hashes like this one: a4ad67ea73c88b635e003700290239e6beab7dc5c9b31f58cd34084418b7316d I would like to convert this hash to raw format (in hexcode). For example, the blockchain API converts this transaction hash…
akd
  • 25
  • 1
  • 5
0
votes
1 answer

Cant install pycrypto module in 3.5.2 version

yesterday, for HOURS, I've been trying to install pycrypto on python 3.7 version. I installed build tools thing, restarted my computer - no success. I decided to uninstall python and install 3.5.2 version, and guess what? I actually managed to…
0
votes
1 answer

AES decryption - java to python code conversion

I am trying to do integration with a Bank API. Here is the Java sample code provided by the bank to do encryption/decryption. package com.example.restservice; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import…
Ranjith Ramachandra
  • 10,399
  • 14
  • 59
  • 96
0
votes
0 answers

Error installing pycryptodome 3.4.3 using pip

I'm running python 3.7.4 and trying to install pycryptodome 3.4.3 using pip. I getting the following error. /usr/bin/ld: cannot find -lpython3.7m Full output Collecting pycryptodome==3.4.3 Using cached…
Bharath Kumar
  • 71
  • 1
  • 5
0
votes
1 answer

pyinstaller (auto-py-to-exe) error: Project output will not be moved to output folder?

python v3.6.8 PyInstaller v3.6 auto-py-to-exe v2.7.5 os: windows 7 Command: pyinstaller --noconfirm --onedir --console --name "MyMainapp" --key "qXx53d02m2PrswB1" --debug "all" "