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
-1
votes
2 answers

How would i fix this error in creating a genesis block

Traceback (most recent call last): File "C:\Users\RAC\crypto\...\blockchain.py", line 178, in blockchain = Blockchain() ^^^^^^^^^^^^ File "C:\Users\RAC\crypto\...\blockchain.py", line 49, in __init__ …
-1
votes
1 answer

Getting error when trying to install pycrypto on Windows 10

I get the following error when trying to install pycrypto with pip install pycrypto. I've passed the last 8 hours trying to fix it. If anyone has a way to install pycrypto without going through pip that would be nice. Currently when I run my Python…
wnetMC
  • 175
  • 8
-1
votes
1 answer

Syntax error on Mac python 3.8 from pycrypto

I am facing Syntax error on Mac python 3.8 from pycrypto, surprisingly its passing on the linux system, i know the alternative was proposed to remove pycrypto and install pycryptodome but i didnt get why the above is working on linux and not on mac…
Manish
  • 31
  • 1
  • 5
-1
votes
1 answer

Install Crypto using pip in windows

I tried with pycrypto, pycryptodome, and crypto seperately.. But it shows ModuleNotFoundError: No module named 'Crypto' python -m venv .venv .venv\scripts\activate pip install pycryptodome pip install pycrypto pip install crypto Installed all the…
Gokul Raghu
  • 55
  • 2
  • 11
-1
votes
1 answer

Incorrect AES key length (356 bytes) while trying to decrypt chrome passwords using python

I am trying to decrypt my chrome passwords from the "Login Data" sqlite file. I followed this tutorial: https://ohyicong.medium.com/how-to-hack-chrome-password-with-python-1bedc167be3d The code is shown here: import sqlite3 from sqlite3.dbapi2…
Archangel
  • 182
  • 1
  • 10
-1
votes
1 answer

Whenever I try to install pycrypto errors comes there

building 'Crypto.Random.OSRNG.winrandom' extension error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/ How to fix it pls anyone help
-1
votes
2 answers

i am getting an error while installing pycrypto in windos 10 in visual studio code

I got this error while installing pycrypto in visual studio code. I tried previous answers it didn't work for me Building wheel for pycrypto (setup.py) ... error ERROR: Command errored out with exit status 1: command:…
-1
votes
1 answer

File "", line 1, in

Unable to install pycrypto Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 07:55:33) [MSC v.1916 32 bit (Intel)] on win32 from Crypto.Cipher import DES ModuleNotFoundError: No module named 'Crypto' How to install pycrypto?
-1
votes
2 answers

How the get N highest numbers?

I have this code and i've to get an aswer that returns me the 10 highest numbers per percent_change_24h from 'r' variable. What method should i use? I've seen max method but that one returns just one value (the highest sure, but only one) …
-1
votes
1 answer

python 3 'function' object is not iterable

I am new to python and I am trying to create a chat server in python using socket. In my server i want to encrypt and decrypt the message sended from the client to the sever.I am trying to create a key from the server then send it to the client but…
son duong
  • 21
  • 6
-1
votes
1 answer

Encrypt data with accents using python crypto library

I am implementing DES3 in Python using Crypto library. I was doing some test when I’ve stumbled upon the next problem: If the plain text that I want to encrypt contains strange charactes, as accents, fails. For example, my code is working fine…
-1
votes
1 answer

PyCryptodome alternative for jython

I am trying to incorporate a simple encrypting processor for Apache Nifi. I am using the Script Processor module to include a Python script that does the function on encrypting and decrypting with AES. I am having trouble loading the module…
jordi
  • 1,157
  • 1
  • 13
  • 37
-1
votes
1 answer

RSA with AES 128

This is my protocol: Encryption and signing - user A cipher using the public key from user B sign the encrypted message with the private key A Verifying and decrypting - user B verify the signature with the public key A decrypt the message with…
Doe
  • 21
  • 1
  • 6
-1
votes
1 answer

how do I use this pycrypto code in pycryptodome

how do I use this pycrypto code in pycryptodome: #!/usr/bin/env python from Crypto.Cipher import AES import base64 import os # the block size for the cipher object; must be 16 per FIPS-197 BLOCK_SIZE = 16 # the character used for padding--with a…
S. Raud
  • 3
  • 4
-1
votes
1 answer

getting different results when encoding with python and when encoding with nodejs

i am trying to encode a particular string with python with pycrypto and encode the same string with nodejs with crypto. i am getting different results in both the cases for the same input string python code: from Crypto.Cipher import AES from…
Ayush
  • 57
  • 2
  • 11