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

"Stopped working" error when installing PyCrypto

I am attempting to install PyCrypto under Windows 7, 64 bit. I downloaded and installed ActiveState's Python 2.7.10.12, 64 bit, without issue. The interactive shell appears to work fine. Next, I went to VoidSpace and downloaded PyCrypto 2.6 for…
NewSites
  • 1,402
  • 2
  • 11
  • 26
0
votes
1 answer

How to write encrypted data in a file using pycrypto?

I have been using RSA Public/Private Key Pair to encrpyt data: random_generator = Random.new().read key = RSA.generate(1024, random_generator) publickey = key.publickey() and write it to a file. The probelm I am getting is when I read any file in…
Manuj Mittal
  • 97
  • 1
  • 2
  • 12
0
votes
0 answers

pycrypto not encrypting in ascii or unicode

I am using pycrypto to encrypt and decrypt a message using a key. I followed some examples and finally wrote my own. But it turns out that the encrypted message is not in unicode or ascii. I need to store the encrypted message on a mysql database…
Himanshu Mishra
  • 8,510
  • 12
  • 37
  • 74
0
votes
0 answers

Can I rescue this corrupted DER format file?

I have two files that represent the same DER format public key. They both look like this when I look at them in a text editor (sublime) 3081 9f30 0d06 092a 8648 86f7 0d01 0101 0500 0381 8d00 3081 8902 8181 00d2 d475 9de6 d795 7d0f e5e8 375f 3605…
David Lewine
  • 101
  • 2
  • 12
0
votes
0 answers

PyCrypto yielding "no commands supplied" error during build

I am a hardcore newb when it comes to computers, but I am doing my best to learn Python. Namely, I'm taking an online Crypto course, and I'm trying to do an assignment which requires PyCrypto. I'm using the 32-bit version of Python 3.5. I…
boldbrandywine
  • 322
  • 1
  • 14
0
votes
1 answer

Problems with encryption when converting Crypt:CBC example from Perl to Python (Blowfish)

I am trying to translate the program below to Python. In the end the Python code should produce the same passphrase output as the Perl variant. #!/usr/bin/env perl use Crypt::CBC; my $key = 'key to the gates'; my $cipher = Crypt::CBC->new( …
0
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
  • 41,341
  • 63
  • 198
  • 344
0
votes
0 answers

pycrypto RC2 encrypt() does not get the right cypher

I have written a simple function to encrypt a message with RC2 in Python. The package used is pycrypto; However the result is not correct, the code as following shown def encrypt_rc2(plain, key): b_size = ARC2.block_size # PKCS7 padding …
Jacky1205
  • 3,273
  • 3
  • 22
  • 44
0
votes
1 answer

RSA generate private key from data with python

I have a cipher message in base64 and a pubkey.pem with the public key information. So because the key is small(576) I have recovered all the needed information to reconstruct the private key : p,q and d. Now I want to decipher the message but I…
Whysmerhill
  • 231
  • 1
  • 2
  • 7
0
votes
3 answers

PyCrypto: Attribute Error: 'NoneType' object has no attribute 'oid' while using PKCS1_v1_5

SHA = hashlib.sha1() Eh = SHA.update(chunk) HRSA.signSHA(Eh,RSAprivatekey) RSAprivatekey is read in HRSA module and passed as argument to this function: RSAprivatekey = RSA.importKey(infile.read()) infile points to the 'privatekey.txt' which…
0
votes
0 answers

Python: Pycrypto decryption error

So currently I have been working on a encryption and decryption program for my school to use, for their database and storing student logon passwords. I am having trouble with this error though. TypeError: a bytes-like object is required, not…
Delusive
  • 11
  • 1
0
votes
1 answer

Encrypt string with AES in Python and IOS

I am trying to encrypt a string with AES in both IOS with CCCrypt and in Python with Crypto. However I seem to get different results. Anyone has any ideas why? I am trying to use 256 bit AES with null IV and CBC. Python code: key =…
sopor
  • 46
  • 7
0
votes
0 answers

Python version 2.4.4 in which it unlocks some features after reading a license file from the path "C:/filename "

I had an application build with the Python version 2.4.4. It unlocks some features after reading a license file from the path "C:/filename ". But it is not working while trying on the other machine with Win-7 OS, while working on other machines…
0
votes
3 answers

how to solve this paramiko import issue?

I have an issue with installing paramiko.. I think It is installed correctly from pip and when I tried to do import paramiko... I got an error.. us159010:site-packages jaehokim00$ python Python 2.6.9 (unknown, Jul 14 2015, 19:46:31) [GCC 4.2.1…
Larry
  • 41
  • 1
  • 4
0
votes
1 answer

python equivalent of the java RSAIO.save

I am using some java code snippets as a reference to work on a python application (2.7.9) I am making. I know the java code parts function correctly, but my python versions are not. I am trying to save a generated RSA key pair (2048 bit) to a file…
user4805123