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
0 answers

CryptoJS to Pycrypto AES

Im trying to decrypt with Pycrypto an encrypted text with CryptoJS, and I would like to know how is generated the by default IV value from CryptoJS?An example code solving the decryption would be great. This is the decryption code with JS: var…
chuseuiti
  • 783
  • 1
  • 9
  • 32
0
votes
1 answer

Convert python cryptography EC key to OpenSSH format

I am looking to convert EC key generated using cryptography module to their respective OpenSSH strings. like ecdsa-sha2-nistp256…
abhi
  • 366
  • 6
  • 17
0
votes
0 answers

Python script needs access to AES key! Looking for safe strategy?

I've written a script that clones new files from a remote server to my raspberry pi. The script automatically runs a couple of times a day and reads the login information for the server from a YAML configuration file. For security reasons, I want to…
St4rb0y
  • 317
  • 3
  • 5
  • 22
0
votes
1 answer

PyCrypto RSA and Pickle

I'm working with pyCrpyto's RSA class: from Crypto.Cipher import PKCS1_v1_5 from Crypto.PublicKey import RSA message = 'To be encrypted' key = RSA.generate(2048) cipher = PKCS1_v1_5.new(key) ciphertext = cipher.encrypt(message) That code runs…
bkaiser
  • 647
  • 8
  • 22
0
votes
2 answers

Using pyCrypto to hash results in a TypeError

I'm trying to use pycrypto for python 3.5.1 on win10 using this simple piece of code for has: from Crypto.Hash import SHA256 SHA256.new('abc').hexdigest() resulting this error: Traceback (most recent call last): File "E:/Python/C.py", line…
Arshia
  • 27
  • 6
0
votes
1 answer

Implementing SJCL .frombits in python

I'm trying to rewrite some JS (which uses the SJCL library) in Python using pycrypto. I'm having trouble figuring out how to implement the following code aes = new sjcl.cipher.aes( this.key ); bits = sjcl.codec.utf8String.toBits( text ); cipher =…
dan
  • 305
  • 1
  • 13
0
votes
1 answer

Django PyCrypto - Save Encrypted String to Database Bad Unicode Data

I'm working with PyCrypto in Django and I need to encrypt a string using the user's secret key they made themselves. I successfully wrote an encryption method as follows: from Crypto.Cipher import AES from Crypto.Random import get_random_string def…
Nick
  • 1,864
  • 5
  • 27
  • 49
0
votes
1 answer

Instances & classes: requiring x arguments when x-1 given

I have written the following classes to be able to test different encryption schemes. However, I'm having trouble instantiating objects from the different encryption scheme. Could someone point out to something that doesn't make sense that I'm not…
user65165
  • 874
  • 1
  • 8
  • 11
0
votes
1 answer

Install Fabric error in pyenv

I want use Fabric when I product my project in AWS Ubuntu. When I read about Fabric, it required python 2.5~2.7, so I create Python virtualenv on Mac OS X: pyenv virtualenv 2.7.5 fabric mkdir fabric and I run pip install fabric (fabric)fabric $ pip…
Jade Han
  • 1,185
  • 5
  • 15
  • 36
0
votes
1 answer

Decrypt cipher text encrypted with PyCrypto using cryptopp

My server encrypts files using pycrypto with AES in CTR mode. My counter is a simple counter like…
Sassan
  • 2,187
  • 2
  • 24
  • 43
0
votes
0 answers

Pycrypto read text file into string and decrypt AES 256

I'm attempting to read a text file into a string and then decrypt that string but it keeps failing and giving the following error ValueError: Input strings must be a multiple of 16 in length I know the encryption works because I've tested it so it…
suroh
  • 917
  • 1
  • 10
  • 26
0
votes
1 answer

JSEncrypt to PyCrypto RSA encryption not possible

I'm trying to encrypt a string in Javascript using RSA (public key) And I want to decrypt that string in Python (2.7) with my private key. The Libraries I am using are JSEncrypt and PyCrypto The Problem here is, that PyCrypto has problems to decrypt…
DarthVader
  • 192
  • 4
  • 16
0
votes
1 answer

Script made compiled with pyinstaller DLL load fail

I have compiled a script with pyinstaller and it compiles fine but when I run the program I get the following error in the console window. ImportError: DLL load failed: The specified module could not be found. I am trying to import Crypto when I…
cdw100100
  • 192
  • 1
  • 13
0
votes
0 answers

Invalid syntax error in pycrypto while importing paramiko

I am getting the following error when I am trying to import paramiko. I am using python3.5 and paramiko 2.6 Traceback (most recent call last): File "paramiko_test.py", line 1, in import paramiko File…
Oliver Blue
  • 677
  • 2
  • 9
  • 22
0
votes
1 answer

Python : Pycrypto RSA public key encryption error

So I've just started experimenting with Pycrypto and wanted to encrypt and decrypt a message, but this code I put together produced some errors. Here they are: enc_data = public_key.encrypt TypeError: unsupported operand type(s) for pow(): 'str',…
AtomiCookiez
  • 61
  • 2
  • 10