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

Reading a private key generated with Putty in ezPyCrypto

I used Putty Key Generator to create a private key, called Putty-Private.ppk. I can use this private key with Pageant and Putty to connect to the servers of my hosting provider. Now, I want to connect to the server with xmlrpc based remote API. To…
Mert Nuhoglu
  • 9,695
  • 16
  • 79
  • 117
0
votes
2 answers

Python 2 encryption program when converted and run in python 3 returns error

This is a continuation of this question. Please do not mark this question as a duplicate for it has a different error I need to fix. TL;DR for the link: So I was asking about a Unicode error in python for my encryption program and someone told me…
Trooper Z
  • 1,617
  • 14
  • 31
0
votes
1 answer

Python encryption unicode error when converting from Python 2 to python 3

I found some code which I want to incorporate into my Python encryption program. It should encrypt the files in the code's same directory, and I want it to target a directory. But, it's written in Python 2 and when I change around some code to fit…
Trooper Z
  • 1,617
  • 14
  • 31
0
votes
0 answers

Pycryptodome: AES CBC mode Error 65537

I have to decrypt Data with AES in CBC Mode and Zero-Byte-Padding. Heres my Code (similar to the one in the Documentation): from Cryptodome.Cipher import AES from base64 import b64decode from Cryptodome.Util.Padding import unpad key =…
SomeDude
  • 11
  • 4
0
votes
0 answers

use a 32 byte initialisation vector in pycrypto

I am trying to decrypt a text using python with pycrypto. But I get: ValueError: IV must be 16 bytes long However my iv is 32 bytes long and I cant change that. My key is also 32 bytes in size Is there a way to do this with pycrypto? I could find…
Jacknife
  • 1
  • 3
0
votes
1 answer

pycrypto massup when install with crypto on mac

I am trying to install crypto and pycrypto in same virtual environment. [root@jnkslave01 tmp]# virtualenv test_pycrypto New python executable in /root/tmp/test_pycrypto/bin/python Installing setuptools, pip, wheel...done. [root@jnkslave01 tmp]#…
Nilesh
  • 20,521
  • 16
  • 92
  • 148
0
votes
1 answer

How to reduce the length of a message encrypted with Hybrid encryption

I was looking for a good encryption scheme to encrypt my message and i founded that the Hybrid encryption is good for large and small messages. but i have a problem with the length of the output cipher message which is large. if the input was…
Ahmed Salama
  • 111
  • 2
  • 6
0
votes
2 answers

Decrypting AES CBC data from PyCrypto with Powershell

I am working on a project where I will be encrypting a string of data using the AES module from PyCrypto and then decrypting it using Powershell. I've written a simple encryption function to do what I need here: import base64 from Crypto import…
dosgatos
  • 43
  • 1
  • 9
0
votes
1 answer

Can't decrypt blowfish CTR file with pycryptodome

I'm trying to recover file encrypted with an old pure python implementation of blowfish. the old code relied on a single blofish.py file (Copyright (C) 2002 Michael Gilfix ) The old data are encrypted performing following operations: cipher =…
Prev-I
  • 61
  • 8
0
votes
0 answers

PyCrypto Library Encrypting vs Decrypting Speed

I am using Pycrypto encrypter and decrypter with AES 256 Symmetric key algorithm. My encryption part is taking much more time in comparison to decryption time. Is there any good reason for it? I tried on 16 MB file: Encryption time = 3.31…
hatellla
  • 4,796
  • 8
  • 49
  • 101
0
votes
0 answers

AES python encryption and Fernet Encryption problem

I run into trouble when making a text encryption program in python I use both AES then I also use FERNET my code is: from cryptography.fernet import Fernet key = Fernet.generate_key() f = Fernet(key) token = f.encrypt(b"this is my…
Snow Angel
  • 31
  • 6
0
votes
2 answers

Using mysql AES encrypt and decrypt from Django

In my Django app, I want to use AES_ENCRYPT and AES_DECRYPT from the mysql database to encrypt and decrypt stuff. I know that python's Crypto package has AES support but the Crypto AES doesn't produce the same result as mysql AES although I made…
Ahmedn1
  • 626
  • 1
  • 9
  • 20
0
votes
1 answer

Convert PasswordDeriveBytes functionality to Python

I'm trying to re-create PowerShell's PasswordDeriveBytes method in python using pycryptodome's KDF module. The main thing I can't get passed right now is getting the correct DerivedKey result in Python that I get from…
gakar06
  • 313
  • 1
  • 4
  • 10
0
votes
2 answers

pycryprodome AES CBC mismatch after decryption in Python

my goal is to have a very simple AES 128 CBC scheme which encrypts a plaintext and then decrypts it based on a given key in Python. I'm using pycryptodome framework and I couldnt find any documentation with an example of the AES CBC scheme.…
0
votes
1 answer

How to slice dict values to different list

import ccxt import time import re exchanges = {'mercado', 'bitfinex', 'quadrigacx','binance'} limit = 10 def get_order_book(key,symbol): exchange = eval('ccxt.' + key + '()' ) orderbook = exchange.fetch_order_book(symbol,limit) print…