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

Insert PyCrypto RSA decrypted text into mySQL db

im tying to import a string from pyCryptos RSA encryption function into a mysql database. The datatype of the column username in the database is varchar(256). here is my code: # coding: utf8 from InstagramAPI import InstagramAPI import…
Tim von Känel
  • 301
  • 2
  • 12
0
votes
1 answer

Encrypting-Decrypting multiple times

I'm trying my hand at Cryptography using Python2.7. I'm able to encrypt-decrypt a text once. But when I try to encrypt-decrypt multiple times, in a loop, it doesn't give back the original string in variable p. Please have a look at my code, and…
0
votes
2 answers

Error 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 1: invalid start byte' decoding bytes after decrypting with pycryptodome

My problem is that when I use pycryptodome for decrypting a string in Python 3.6 with the following code: from Crypto.Cipher import AES from Crypto import Random key = "133BBB3212332231" key_bytestring = key.encode("utf-8") iv =…
edusan1213
  • 359
  • 5
  • 15
0
votes
0 answers

PyCrypto encryption/decryption error client/server and CHIL engine

I have two sides: one or more clients, running Python 2.7.10, Pycrypto 2.6.1 one server, running the same all running on: django 1.11.2, Centos 6.9, OpenSSL 1.0.1e-fips the server holds an HSM-backed private key and the corresponding public…
Hal
  • 537
  • 4
  • 13
0
votes
1 answer

Pycrypto: How to view raw RSA signature data?

I'm working with a service that uses raw RSA with a private key to sign a payload. The data is effectively produced using: openssl rsautl -inkey private_key.pem -raw -sign (Also, the result of encrypting with the private key) Unfortunately, in…
Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
0
votes
0 answers

Python - Socket sends RSA public key wrong

I trying implement a simple messaging system with several security features. So I need to send client's RSA key's public key part to server. But I print key on both sides. They are not match. My client code: from Crypto.PublicKey import RSA from…
Şaban Kaya
  • 31
  • 1
  • 8
0
votes
2 answers

Pycrypto on RHEL Fails

I am trying to install pycrypto via pip. The installation fails with: Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-zWtfwz/pycrypto/setup.py';f=getattr(tokenize, 'open',…
k1DBLITZ
  • 121
  • 1
  • 7
0
votes
2 answers

"could not import Crypto" running "conda install numpy"

In the Linux subsystem for Windows10 I have encountered a new error when trying to conda install, update, remove any new package. For example: c/.../...$ conda install numpy Error: could not import Crypto (required for signature verification). …
0
votes
1 answer

Unable to install pycrypto on ubuntu 14.04 with python3

I'm trying to install stream package with pip install stream_django which has pycrypto dependency. So while installing pycrypto dependecy it returns me RuntimeError: autoconf error error. How can i install pycrypto on ubuntu 14.04 with python3
0
votes
1 answer

Base64 encoded output differs from as3crypto and pycrypto encryption libraries

I'm trying to use symmetric encryption to pass data from actionscript 3 (client) to python (server). The libraries I'm using are as3crypto and pycrypto, I'm not sure if I'm using these libraries correctly. Actionscript 3: private function…
0
votes
1 answer

How to RSA encode large data in python 3

I try to encrypt data with python3.x using pycrypto library. It works fine for short data but not for long arrays. How can I encrypt long data? Should I write a wrapper to split data smaller chunks? Or is there any other crypto library that can…
betontalpfa
  • 3,454
  • 1
  • 33
  • 65
0
votes
2 answers

Integrity check causes AES decryption to fail in Python 3

I'm currently working on a simple encryption and decryption tool using pycryptodome and its AES cipher. But there is a problem when padding the plaintext to the size of a block. Usually people do it by adding zeros. But what happens when the last…
chrizator
  • 93
  • 1
  • 10
0
votes
0 answers

Different output for same statement run twice in python shell using pycrypto library

I was experimenting with pycrypto library with below setup. OS: Ubuntu 16.04.2 x86_64 Python Version:2.7.12 pycrypto version: 2.6.1 I am not able to understand why there is a difference in output of 2nd last and 3rd last statement though both are…
Blue Bird
  • 35
  • 6
0
votes
1 answer

PyCrypto AES suddenly stops decrypting after several lines of processing input

I am attempting to encrypt and decrypt 5-14 MB text files with two Python files, one containing encrypt/decrypt methods and another being a runner for those methods. Here's the class file: from Crypto.Cipher import AES from Crypto import…
alexdloia
  • 3
  • 4
0
votes
1 answer

Error Python 3.6, WIN10 , Error Installing pycrpto

I have a problem with installing a library (pycrypto, using "pip install pycrypto") in python 3.6 (windows 10). i have searched about my problem and some answers says that i need to install this…
Hamad R
  • 3
  • 1