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

How to solve 'dynamic module does not define module export function' error in Xcode kivy-ios?

I am trying to package a python app in iOS. The app is very simple with just 1 line: from firebase import firebase I follow the instruction from this link: https://github.com/kivy/kivy-ios Firebase would need pycrypto. So I typed ./toolchain.py…
0
votes
1 answer

Decrypt function only returns partial string and not the entire value

I'm writing a test script which I'm using to try and decrypt an encrypted string I have the key to. However, while the code somewhat runs, it is not printing the full string/value that I am expecting (and know the result for). For example, rather…
MrY
  • 13
  • 3
0
votes
1 answer

Unable to build pycrypto recipe in python3 - toolchain

I am trying to package a simple Kivy app in iOS using the instruction in the site: https://github.com/kivy/kivy-ios My app is very simple with 1 line: from firebase import firebase The app can be packaged successfully in android using linux.…
0
votes
1 answer

How to resolve 'Invalid PKCS8 header error' in AWS lambda

I am trying to perform jwt.encode on a small request message with a private key that I am retrieving from DynamoDB. My work station is Mac OS. The code works in my local environment but failed when I tried to execute it in AWS lambda python3.7…
user1655072
  • 572
  • 2
  • 10
  • 20
0
votes
2 answers

Decryption from RSA encrypted string from sqlite is not the same

I am using RSA with private/public key. I am trying to encrypt a string, save it in a database (sqlite) and then retrieve it again and encrypt. I can't decrypt the data again when it is coming out of the sqlite. The string is identical and I am a…
bert2002
  • 67
  • 1
  • 1
  • 6
0
votes
1 answer

How to store, verify and use a key for encryption/decryption in Python and SQLite

Intro: I am trying to practice Python and Crypto by writing a simple Local Password Manager with Python and SQLite. The problem starts during registration. The user enters a Master Password which I keep in a table in SQLite after being hashed 1 time…
C0DEV3IL
  • 27
  • 6
0
votes
0 answers

ImportError: cannot import name 'winrandom'

I know that this question has already a ton of answers but unfortunately this hasn't fixed the issue for me. I want to run some code using PyCrytpo but winrandom doesn't want to get import. All the other posts are for earlier releases of python. I…
0
votes
0 answers

"Ciphering services not available" error with SNMP V3 usage of pysnmp in python v3 virtual environment

I am trying to use pysnmp library with SNMP V3 settings with MD5 Auth protocol and AesCfb128 Priv protocol to obtain details from a switch. I am trying two things. 1. Install pysnmp and all dependency packages (including pycrytpto) in base…
ICK Geek
  • 13
  • 3
0
votes
1 answer

from Crypto.Cipher import AES / ModuleNotFoundError: No module named 'Crypto'

I am not able to run my code, this error appears. I've tried in several ways to install pycrypto. pip install pycrypto -> PyCrypto -> Crypto -> crypto -> pycryptodome .... and so on. Some help?
felipi
  • 139
  • 1
  • 15
0
votes
1 answer

Decrypt base64 ciphertext with nodejs

I have this…
Stefano Sambruna
  • 767
  • 2
  • 10
  • 29
0
votes
0 answers

Get the counter value after decrypt finished

I am trying to decrypt AES-CTR in SSH using the keys generated by the openssh/openssh-portable library. I extracted the keys successfully from memory. Now, after some printfs and research I found out that it seems like the initial counter is…
JustPlayin
  • 89
  • 11
0
votes
1 answer

How to sign data with encrypted RSA private key (AES-256-CBC) in python

Partial example of private_key (this variable is a string): -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: AES-256-CBC,hidden_text.. lots_of_hidden_text.. -----END RSA PRIVATE KEY----- When I try to do the following: from…
gs202
  • 58
  • 6
0
votes
1 answer

Whenever I use with pycrypto it deletes the file

I found some code online that is supposed to encrypt and decrypt files, but whenever I use it, it encrypts the file then when decrypting the file, it just deletes the file when it's decrypting it The program gives me different outputs when the text…
Some_dude
  • 139
  • 1
  • 8
0
votes
2 answers

Python Pycryptodome encryption throws "Ciphertext with incorrect length" error

In continuation to my previous pycryptodome question my requirement now got changed to support 90G of data for encryption. So I have done some design changes, de-factoring the encryption code and make them all run in the subprocess. tar zcvf -…
Ibrahim Quraish
  • 3,889
  • 2
  • 31
  • 39
0
votes
1 answer

Generating RSA and writing to file

why do i get exception in this code: I get output: [*] Error creating your key [*] Error creating your key import os, hashlib from Crypto.Cipher import AES from Crypto.PublicKey import RSA raw_key = RSA.generate(2048) private_key =…
stacks
  • 221
  • 3
  • 13