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

Python - trying to install PyCrypto and MySQL-python in Windows and VisualStudio9

I have visual studio installed and for example I can install lxml but it does not work for PyCrypto and MySQL-python. I am getting following error: File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile self.initialize() …
Efrin
  • 2,323
  • 3
  • 25
  • 45
0
votes
0 answers

How to store a private key used in a web-app securely?

I'm using pycrypto to encrypt information from a web app before persisting it to a database. I need to be able to retrieve the information later, so hashing isn't an option. If my server is compromised, I assume key(s) stored are also…
okoboko
  • 4,332
  • 8
  • 40
  • 67
0
votes
1 answer

As3Crypto (flex) with PyCrypto - how to make AES work?

I have a client in Flex and a server in Python and i'm trying to make AES work between them but for some reason it doesn't work. My server code: import sys from Crypto.Cipher import AES from binascii import hexlify, unhexlify BS = 16 pad = lambda…
Ofir
  • 1,565
  • 3
  • 23
  • 41
0
votes
1 answer

AES Decryption in python

I'm sending credential from front-end using $.ajax method and i used to encrypt credentials using crypto.js. javascript code var encrypted = CryptoJS.AES.encrypt("Message", "This is a key123", { mode: CryptoJS.mode.CFB}); $.ajax({ type:…
Jaydipsinh
  • 491
  • 1
  • 9
  • 27
0
votes
2 answers

Pycrypto - Encrypt on Linux / decrypt on Windows

I've got a encryption/decryption class that I'm using cross platform. I'm using the same class on both server and client. I encrypt a file on a Linux server, then decrypt on either a Linux or Windows client. I have no problems when decrypting on…
djtaylor
  • 1
  • 2
0
votes
1 answer

How to import relative Python package (pycrypto)

I am new to Python (as of today) and having trouble following this example for AES: https://pypi.python.org/pypi/pycrypto/2.6.1 using Python 3.3 from Crypto.Cipher import AES I downloaded the package from here…
Dominic
  • 62,658
  • 20
  • 139
  • 163
0
votes
1 answer

pycrypto AES-CTR implemention with custom counter increment

I need to implement AES-CTR decryption with the custom counter increment. To do this, Reading encrypted data form the file. (File data is given below) Getting first 8 bytes for the nonce. Next two bytes for the increment counter for the…
DumbGuy
  • 1
  • 2
0
votes
3 answers

Is there any library or code for DES which take 7 byte key?

Do we have any library or any mechanism where we can use true 7 byte key for DES instead of 8 byte key. I need it for keys analysis in DES and 8 byte key requirement for associated library is creating problem in getting actual keys analysis.
ceasif
  • 345
  • 2
  • 14
0
votes
1 answer

DES Encryption and decryption of hex using hex key python

How can I encrypt and decrypt hex text using 8 byte hex key using DES algorithm in python? I have a hex text 0x3a3456abcd4ff5cd to encrypt with hex keys so how can I convert these values to equivalent strings so that I can use existing libraries to…
ceasif
  • 345
  • 2
  • 14
0
votes
0 answers

Spurious keys filter

Is there any possible way to filter a key space in a crypto-system to get a set of keys that decrypts out a valid text (text that is in same language or readable)? I tried a random approach and got certain set of keys but its not that appreciative…
ceasif
  • 345
  • 2
  • 14
0
votes
1 answer

Shared Server: Python Script run under UNIX Shell vs HTTP

I have a Python script on my Dreamhost shared server. When I access my script via SSH (using the UNIX Shell) my script executes fine and is able to import the Pycrypto module Crypto.Cipher. But if I access my script via HTTP using my websites url.…
Mack
  • 593
  • 1
  • 5
  • 7
0
votes
1 answer

how to install python package in Raspbian?

I'm trying to install pycrypto for python 3.x.x on raspberry pi but when i run python setup.py install from the command line, it is by default installed to python 2.7.x i have installed python-dev and still with no luck, i have read that using a PIP…
0
votes
1 answer

Python Encryption - Unexpected Variable Return

I am currently having an issue of not being able to decrypt the text provided after encryption. It returns: Key: ンƚ!*!゙ᆱø}Qd`Dᆱd!Þxͦ}ᄚミᄀ>'U Unpadded Text: Hello World Padded Text: Hello World Salt: h5eE0b814M Encrypted Text:…
0
votes
0 answers

Pycrypto installation failing on Travis CI

I am getting a UnicodeDecodeError on my Travis CI build during pip install pycrypto. Traceback (most recent call last): File "/home/travis/virtualenv/python2.7/bin/pip", line 11, in sys.exit(main()) File…
Ruslan Osipov
  • 5,655
  • 4
  • 29
  • 44
0
votes
2 answers

no acceptable C compiler found in $PATH on google compute engine

When I try to install pycrypto on a GCE i get the error "no acceptable C compiler found in $PATH". I use pip like this pip install pycrypto The GCE is a backports-debian-7-wheezy-v20131127 image. I assumed the debian image would have gcc installed,…
erickCo
  • 212
  • 2
  • 11