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

Unable to verify a signature in python using PKI

I am struggling to port the following java code to python. I am using PyCrypto to read the publickKey but it fails with an assertionError: keyDER = b64decode(publicKeyBase64) seq = asn1.DerSequence() seq.decode(keyDER) keyPub = RSA.construct(…
Abhi
  • 261
  • 1
  • 3
  • 12
0
votes
2 answers

PyCrypto AES encryption not working as expected

I am creating a Python function to perform counter mode encryption using the PyCrypto module. I am aware of the builtin, but want to implement it myself. I'm trying Test Vector #1 from RFC 3686, and have the correct Counter Block and the correct…
LonelyWebCrawler
  • 2,866
  • 4
  • 37
  • 57
0
votes
1 answer

Virtualenv PyCrypto cannot import Crypto modular

Python, Django 1.3.5 I am using virtualenv, sudo pip install PyCrypto==2.6, which succeed. But Django's error: Traceback (most recent call last): File…
0
votes
1 answer

Pass list to AES key generator in PyCrypto

I'm attempting to generate an AES key with Pycrypto but receive the following error: TypeError: 'list' does not support the buffer interface for the following statement: aescipher = AES.new(mykey, AES.MODE_ECB) mykey, is of type list and contains…
keekers
  • 33
  • 4
0
votes
2 answers

PyCrypto not Working on Python 3.2

I have PyCrypto version 2.6 and I have read from the changelog that 2.4 or later version of PyCrypto Supports Python 3. I tried to install it using # python3 setup.py install But it gives me this error running install running build running…
Chitrank Dixit
  • 3,961
  • 4
  • 39
  • 59
0
votes
1 answer

pycrypto develoment server error "from Crypto.Cipher import blockalgo"

I have installed pycrypto version 2.6 , and i am getting this error from Crypto.Cipher import blockalgo ImportError: cannot import name blockalgo I have read many post but i am unable to solve this problem
Nishant Nawarkhede
  • 8,234
  • 12
  • 59
  • 81
0
votes
1 answer

Errors when including DES.pyd in python 2.6 solution

I have installed Python 2.7 on my windows 7 x64 system with PyCrypto 2.5 compiled and built in. In my install path of D:\Python27\Lib\site-packages\Crypto\Cipher I see DES.pyd. I have opened it with dependency walker and ensured it had initDES as…
0
votes
1 answer

How come I can't decrypted my AES encrypted message on someone elses AES decryptor?

from Crypto.Cipher import AES import os key = 'mysecretpassword' iv = os.urandom(16) plaintext1 = 'Secret Message A' encobj = AES.new(key, AES.MODE_CBC, iv) ciphertext1 = encobj.encrypt(plaintext1) encryptedText =…
user299648
  • 2,769
  • 6
  • 34
  • 43
0
votes
4 answers

Error in installing pycrypto-2.3 on fedora 15

Hi i am trying to install pycrypto-2.3 from here I downloaded and run the following command cd pycrypto-2.3/ python setup.py install I am getting the following error, running install running build running build_py creating build creating…
Shiva Krishna Bavandla
  • 25,548
  • 75
  • 193
  • 313
0
votes
1 answer

Encryption of a JPG file using pycrypro's AES failing

Given below is the code(not complete yet) I have written to encrypt and decrypt files using python with the pycrypto module. from Crypto.Hash import SHA256 from Crypto.Cipher import AES import getpass class ED(object): def…
ritratt
  • 1,703
  • 4
  • 25
  • 45
0
votes
1 answer

Java Python Message Signature and Verification

My server is coded in Python and I am making a java client for this server. I am Signing a message(data) using: public static byte[] Sign(PrivateKey privateKey, byte[] data) throws Exception{ System.out.println("Signing the key inside…
d34th4ck3r
  • 719
  • 2
  • 11
  • 38
0
votes
3 answers

PyCrypto: Encrypt an string twice using RSA and PKCS#1

Hello everyone. I was wondering if it's possible to do a double RSA/PKCS#1 encryption with PyCrypto. I have a server that has its own RSA key (generated with the openssl command when said server is installed) and a client which can request the…
Savir
  • 17,568
  • 15
  • 82
  • 136
-1
votes
1 answer

Cannot import name 'winrandom'

I am having trouble running codes that utilize Paramiko and break with the error in the title. PyCrypto for Python 3.4 on Windows 8.1 cannot find winrandom module I've tried this solution but it doesn't work. Almost all posts related to this problem…
N Trn
  • 1
-1
votes
1 answer

How do I solve the there is no Crypto package error in Python?

I am having an error in my Python code, basically I need to import the package Crypto and I have tried to download it, it says that the package crypto has been installed then keeps showing the same error. I have tried to rename the package from…
-1
votes
1 answer

What is the difference between two strings in Python?

I perform an operation on several strings in a Python function and return the final value with the name of the result I use the result value in another file to encrypt or sign with the RSA algorithm The problem is that the output of the algorithm is…
Navrang
  • 41
  • 4