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 encrypt/decrypt, losing part of encrypted string when decrypting

I am trying to encrypt/decrypt with pycrypto in python. for the most part things have worked smooth but I am getting an odd problem when decrypting data.I have tried to encrypt/decrypt some jpgs for testing and although they encrypt/decrypt without…
mypython
  • 3
  • 4
0
votes
0 answers

Crypto.js equivalent module in python for AES encryption and decryption

I am trying to decrypt a file in python which was encrypted using CryptoJS(AES) in Node.js. I know there is an equivalent module in python (Pycrypto) but I don't know how to use it or which mode of AES decryption to use for decrypting the data(I…
0
votes
1 answer

Different outputs from openssl command and pycrypto when encrypting with Triple DES in CFB mode

I'm now trying to encrypt some plain texts with given 3 keys and initialization vector (iv) with Triple DES algorithm in CFB mode. My implementation in python using pycrypto is as follows. import base64 from Crypto.Cipher import DES3 key1 =…
user6344468
0
votes
1 answer

Two ways of printing a SHA-256 hash differ in 1 byte in Python

Consider the snippet: from Cryptodome.Hash import SHA256 text = b'Jeanny' print('Hash of', text) hx = SHA256.new(text).hexdigest() print(hx) h = SHA256.new(text).digest() [print('{0:x}'.format(h[i]), end = '' ) for i in range(0,len(h))] It…
P. Wormer
  • 377
  • 3
  • 11
0
votes
1 answer

pycharm project to exe conversion

I was using Pycharm for the development of my python project which involved libraries like win32api and Pycrypto, what is the best way to create an exe out of pycharm, using abnaconda interpreter? please note that Cx_Freeze is not available while…
0
votes
0 answers

Python modules do not load. - PyCrypto

I've written an encryption script with PyCrypto in Python 2.7. However, when trying to convert to an executable file, Crypto does not load and the program shuts down immediately. I've tried PY2EXE, Pyinstaller, and CX_Freeze. i want to know how to…
AWP
  • 3
  • 3
0
votes
0 answers

Python RSA decryption is throwing error

from Crypto.PublicKey import RSA from Crypto.Signature import PKCS1_v1_5 from Crypto.Hash import SHA from base64 import b64decode def wesocket_Data_Receive(request): Data=request.GET.get('ContentData') key…
0
votes
1 answer

Crypto Random not working?

I'm trying out AES encryption on Python and my code is fine but in from Crypto import Random, the Random is giving an error. When I run the code, I get the following traceback: Traceback (most recent call last): File…
RedCode
  • 363
  • 1
  • 6
  • 23
0
votes
1 answer

TypeError when creating a SHA512 hash using pyCryto

Evening All, I am wanting to verify a a file using Public Key crypto and I cant figure out why I'm getting a Type error for the below code, note signatureLength = 512 signature = f[:signatureLength] f = open('lib/publicKey.pem','rb') publicKey =…
0
votes
1 answer

PyCrypto Not Printing Properly

Hi so before I was getting the IV in front (decrypted value of IV I believe it was) of the decrypted string. Now I don't get the string... How do I make this work, been trying for hours now... My code: from Crypto.Cipher import AES import…
0
votes
1 answer

Skipping elif statement?

Am trying to create a simple encryption/decryption using pycryptodome but keeping getting the following error: ValueError: Error 3 while encrypting in CBC mode after some digging I saw that you get this error if there is not enough data to encrypt,…
0
votes
2 answers

Using Pycryptodome library for python, I am getting a TypeError: Only byte strings can be passed to C code" whenever I try to decrypt

def aes128_decrypt(self, msg): iv = os.urandom(16) aes_obj = AES.new(self.key, AES.MODE_CBC, iv) decrypted_msg = aes_obj.decrypt(msg) return decrypted_msg I am using this to decrypt and msg is being passed in as a bytearray. I am…
user2063496
  • 75
  • 1
  • 1
  • 6
0
votes
0 answers

Pycrypto for windows 7 python 3.5

Ok so i am trying to encrypt /decrypt a .txt file as part of a longer script. So i am trying to install PyCrypto for windows 7 64bit python 3.5 using this link, https://github.com/sfbahr/PyCrypto-Wheels. But alias keeps failing. With the a bit of…
little sue
  • 11
  • 1
0
votes
0 answers

Understand pycrypto example

As an example, encryption can be done as follows: >>> from Crypto.Cipher import AES >>> from Crypto import Random >>> >>> key = b'Sixteen byte key' >>> iv = Random.new().read(AES.block_size) >>> cipher = AES.new(key,…
0
votes
0 answers

Unable to install pycrypto, error "TypeError: unorderable types: NoneType() >= str()"

I have MingW and I am on Windows 10 with Python 3.5. I have done every thing guides say to do. Do any of you know how to fix this?
apoorlydrawnape
  • 288
  • 3
  • 12