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

Is it possible to encrypt a bytes stream using PyCrypto?

I'm working on an app where users upload a file and the app processes it automatically for them. For data security, I want to encrypt these files. These files can be of varying sizes from small to very large (2MB to upwards of 30MB). I came across…
Vaibhav
  • 507
  • 2
  • 4
  • 20
0
votes
0 answers

Python decryption not matching .NET encryption

Python Encryption: salt = 16 * b'\0' keyIV = PBKDF2(Config.SECRET, salt).read(48) key = keyIV[:32] iv = keyIV[-16:] aes = AES.new(key, AES.MODE_CBC, iv) # padding length = 16 - (len(textToEncrypt) % 16) print(len(textToEncrypt)) textToEncrypt +=…
nblandfo
  • 31
  • 8
0
votes
1 answer

Openssl 1.0.2p decryption failing?

I am using 1.0.2p to encrypt the file using the following command. #openssl aes-128-cbc -e -k 'abcdefghijklmnop' -in my.txt -out myencrypt.txt My decryption is based out of Crypto.Cipher python module. Here is my code. However, I am unable to…
user11473963
0
votes
1 answer

PyExc_ValueError and Firefox extension

I'm developing a firefox addon which is depended on Python (which means that the user must install PyXpcomExt on his firefox). On the other hand I used PyCrypto lib (based on python) for encryption purposes. So when firefox is loaded I have…
sgres
  • 1
0
votes
1 answer

Unable to encrypt data in python3 properly

Hi i have written a code in python2 with pycrypto to encrypt and decrypt from a string here is the code hex_key_bytes = array.array('B', [0xb8, 0xf4, 0xc9, 0x57, 0x6e, 0x12, 0xdd, 0x0d,0xb6, 0x3e, 0x8f, 0x8f, 0xac, 0x2b, 0x9a, 0x39]); # Python…
0
votes
1 answer

Can't install mist or pycrypto on python 3.6

Whenever I try to run pip install mist, it shows me this error. ERROR: Failed building wheel for pycrypto Running setup.py clean for pycrypto Failed to build pycrypto Installing collected packages: pycrypto, ansible, mist Running…
user11697050
0
votes
0 answers

Length of IV wrong but generated by host

I register an upload with an application. I get this back: {'enabled': 'true', 'cipher': 'aes-128-cbc', 'key': 'baa47c89079830de8cc0685374391280', 'iv': '4ba4dcfde54a05296392706f9200b1fe'} Then I do: UPLOAD_ENCRYPTION =…
Daniel Dow
  • 487
  • 1
  • 7
  • 20
0
votes
1 answer

Python AES encryption program is returning Memory Error

So i am following a tutorial on AES implementation with python. It is an project which demanded to implement aes. Following is the code in Python which works fine on small files , but it i tried it ona 1 gb file and then the following error occured…
0
votes
0 answers

How to encrypt in javascript and decrypt in python?

I am trying to encrypt in javascript using cryptoJS and decrypt in python but some how I am unable to get this working.Here is my code : //encrypting in javascript using cryptojs var message = "praveen"; var key = 'This is a key123'; var iv = 'This…
0
votes
2 answers

PyCharm IDE will not load from Crypto.Cipher import AES

I can run python3 myfile.py on the MAC OS command line and it works fine, but inside the IDE, I get the following error. I have done the pip uninstall pycrypto pip install pycrypto This has no effect inside the PyCharm IDE, but it does work with…
DenisMP
  • 973
  • 2
  • 16
  • 31
0
votes
0 answers

Decrypt pcap RC4 encryption with pycrypto

Part of a training exercise I'm doing I need to decrypt data transmitted and saved in a pcap. I know the encryption is RC4 and I have the key which I know is correct I wrote a really basic python script using pycrypto which I thought would do it…
Tavar
  • 1
  • 2
0
votes
1 answer

TypeError: argument must be string or read-only buffer, not bytearray

I'm building a decryptor using DES ECB from Crypto.Cipher import DES code = 'cb9108614c943d96bedd2bae934c5aa3d5c4318f81cc81f255127292f2935bbc0a8990f36c1ffa20a0639ed8a6989bacc36bd11f6b2ecdab' key = b'5199D19B' code=…
Emma Bell
  • 11
  • 1
0
votes
1 answer

Module 'Crypto.PublicKey.RSA' has no attribute 'import_key'

I have a C# application that uses following public keys to encrypt and decrypt (using corresponding private key) successfully. I am using the same Public Key in Python to encrypt, using following code. I am getting following error: module…
LCJ
  • 22,196
  • 67
  • 260
  • 418
0
votes
1 answer

How to fix Python import error for Crypto.Signature.DSS

I am trying to run the pycryptodome example for DSA. Here is the example code: from Crypto.PublicKey import DSA from Crypto.Signature import DSS from Crypto.Hash import SHA256 # Create a new DSA key key = DSA.generate(2048) f =…
arnobpl
  • 1,126
  • 4
  • 16
  • 32
0
votes
0 answers

How to decrypt a text by cryptography which is encrypted by pycrypto in AES CTR mode

I need to decrypt an FTP password encrypted by pycrypto in AES CTR mode ,and for some reason I have to use cryptography instead,so how to do the decryption? I want to know what is the nonce of cryptography should be? this is the encrypt code by…
Ragnarok
  • 1
  • 1