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
-1
votes
1 answer

Python: Encrypting file contents using a password and decrypting it by users

I already read a lot about this topic but I don't really understand how I should implement this. I want to encrypt a (text) file of a user A. The user has set up a password for his/her account and the text file is being encrypted with this password.…
fameman
  • 1,737
  • 10
  • 28
-1
votes
1 answer

How to encrypt multiple files in Python 2

I've been creating a data-protection program which encrypts all files on a computer using SHA-256. So far, the program is capable of encrypting one specified file (that has been hard-coded into the program) at a time and appending a .enc extension.…
Chris
  • 19
  • 4
-1
votes
1 answer

Card Game in Python For Crypto Project

I'm workin on a cryptography project and I want to create a simple high-card game of 2-players using the concept of "Mental Poker" in python. For example a part of the concept is : Each player produce an ri(like a key) and then computes E(ri) (…
-1
votes
2 answers

How to decrypt an AES encrypted data with key and iv already provided

I am trying to decrypt an AES encrypted data. I am having the key and iv with me but I think key is also encoded. Here is the code I have used: import binascii from Crypto.Cipher import AES enckey = '5f35604280b44dd1073f7ee83e346d81' key =…
Mayank Raj
  • 32
  • 5
-1
votes
1 answer

Pycrypto AES encryption throwing two errors

I created a small script to encrypt and decrypt a file, however the file is zero bytes and the decrypted file is not created Code: from hashlib import md5 from Crypto import Random from Crypto.Cipher import AES import os from Crypto import * def…
SDurrani
  • 33
  • 5
-1
votes
1 answer

ImportError: No module named 'Crypto.HASH' but pycryto installed

I am trying to load pycrypto module. When I do import Crypto I get no error but when I do from Crypto.HASH import SHA256 , I am getting ImportError >>> import Crypto >>> hash = SHA256.new() Traceback (most recent call last): File "",…
rɑːdʒɑ
  • 4,209
  • 10
  • 34
  • 67
-1
votes
1 answer

How to decrypt a RC2 ciphertext?

Python 3.5, pycrypto 2.7a1, Windows, RC2 ciphering Example: print('Введите текс, который хотите зашифровать:') text = input() with open('plaintext.txt', 'w') as f: f.write(text) key = os.urandom(32) with open('rc2key.bin', 'wb') as keyfile: …
Tukanoid
  • 61
  • 1
  • 3
  • 9
-1
votes
1 answer

AES decryption fails when decrypting a second time

I have this implementation of a reversible encoding: # coding=utf-8 from Crypto.Cipher import AES from Crypto import Random import uuid import unittest import random key = r'Sixteen byte key' # Keep this real secret iv =…
blueFast
  • 33,335
  • 48
  • 165
  • 292
-1
votes
1 answer

RSA authentication Android java client, app engine pycrypto server, encoded private key

I have an Android client sending RSA-signed messages to an App Engine server using Python and the pycrypto library. The server creates the key pair and sends the private key, encrypted, to the client. I am having trouble unpacking the received key…
-1
votes
1 answer

function encrypt file - input & output to same file in python

i have this script : http://pastebin.com/JypqErN5 in this moment the function working input output file : encrypt_file(in_file, out_file, password): need input output to same file, simile to this : encrypt_file(in_file, password): im try to make…
pythoncoder
  • 37
  • 1
  • 2
  • 8
-1
votes
1 answer

pycrypto is slow encrypting and decrypting

In practice, I select an executable. Size 20Mb. I read the content using file.read(size=16). If length of the returned byte string is less than 16 I fill the rest with \0 (NULL). f = open("./installer.exe","rb") obj =…
user1629569
  • 641
  • 1
  • 4
  • 16
-1
votes
1 answer

Python pycrypto AES File block encryption fails

I am reading 64kb from a generated text file "generated.txt" and writing the data to txt files at the beginning of every written txt file there is strange data, except at the first written file. The generated test file Script to generate the…
D3473R
  • 189
  • 1
  • 4
-1
votes
2 answers

No handlers could be found for logger "paramiko.transport"

I am running some fabric tasks inside of flask. Flask is running inside of wsgi in apache. Once in a while I get this error in the apache logs: No handlers could be found for logger "paramiko.transport" I then have to restart apache for the fabric…
Brian Carpio
  • 443
  • 1
  • 8
  • 15
-1
votes
1 answer

Pycrypto importkey

I am running into a problem with pycrypto public key encryption. Encryption works fine when I have the private key, but when I import just the public key encryption fails: In [85]: import Crypto.PublicKey.RSA In [86]: key =…
-2
votes
1 answer

AES-128 symmetric key cipher.using python

I am trying to finding the remaining part of the key by brute-forcing the remaining 4 characters. Then we decrypt using each key and check if the decrypted message has "Salam" at the starting. from Cryptodome.Cipher import AES def revpad(s): …
1 2 3
56
57