Questions tagged [pycryptodome]

Questions about the usage of the PyCryptodome Python package in programming. PyCryptodome is a self-contained Python package of low-level cryptographic primitives. It is a fork of of the PyCrypto project and it is designed to replace it, since PyCrypto is not being maintained anymore. The package contains a wide collection of secure hash functions and various encryption algorithms, and it also provides support for random generation.

About PyCryptodome

PyCryptodome is a self-contained Python package of low-level cryptographic primitives, created as a fork of PyCrypto.

PyCryptodome exposes almost the same API as the old PyCrypto so that most applications will run unmodified. See this page from the official website for more details.

It supports Python 2.6 or newer, all Python 3 versions and PyPy.

Official resources

Installation

From the PyCryptodome repository:

The installation procedure depends on the package you want the library to be in.
PyCryptodome can be used as:

  • an almost drop-in replacement for the old PyCrypto library.
    You install it with:

    pip install pycryptodome   
    

    In this case, all modules are installed under the Crypto package. One must avoid having both PyCrypto and PyCryptodome installed at the same time, as they will interfere with each other.

    This option is therefore recommended only when you are sure that
    the whole application is deployed in a virtualenv.

  • a library independent of the old PyCrypto. You install it with::

    pip install pycryptodomex   
    

    In this case, all modules are installed under the Cryptodome package. PyCrypto and PyCryptodome can coexist.

For faster public key operations in Unix, you should install GMP in your system.

Differences from PyCrypto

From the PyCryptodome repository:

It brings the following enhancements with respect to the last official version of PyCrypto (2.6.1):

  • Authenticated encryption modes (GCM, CCM, EAX, SIV, OCB)
  • Accelerated AES on Intel platforms via AES-NI
  • First class support for PyPy
  • Elliptic curves cryptography (NIST P-256 curve only)
  • Better and more compact API (nonce and iv attributes for ciphers, automatic generation of random nonces and IVs, simplified CTR cipher mode, and more)
  • SHA-3 (including SHAKE XOFs), SHA-512/t and BLAKE2 hash algorithms
  • Salsa20 and ChaCha20 stream ciphers
  • scrypt and HKDF
  • Deterministic (EC)DSA
  • Password-protected PKCS#8 key containers
  • Shamir's Secret Sharing scheme
  • Random numbers get sourced directly from the OS (and not from a CSPRNG in userspace)
  • Simplified install process, including better support for Windows
  • Cleaner RSA and DSA key generation (largely based on FIPS 186-4)
  • Major clean ups and simplification of the code base

PyCryptodome is not a wrapper to a separate C library like OpenSSL. To the largest possible extent, algorithms are implemented in pure Python. Only the pieces that are extremely critical to performance (e.g. block ciphers) are implemented as C extensions.

270 questions
0
votes
0 answers

AES encryption in python and decrypting in ReactJs

I have Encrypted a string in python using pycryptodome lib and I want to decrypt the string in react using cryptoJs, but I could not find any proper way to do that. this is my code in python: def encrypt_string(string): aes = AES.new(secret_key,…
Fateme
  • 1
  • 2
0
votes
1 answer

Having an issue installing Pyrebase

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pycryptodome Running setup.py clean for pycryptodome Failed to build pycryptodome ERROR: Could not build wheels for pycryptodome,…
UserBen
  • 21
  • 3
0
votes
0 answers

Couldn't build wheel because of a package despite it already being installed windows

I tried to pip install django-warrant and got the following error when it tried building the wheel for pycryptodome: note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for…
aids
  • 19
  • 3
0
votes
1 answer

Try-and-Increment method of ECC generator creation with Pycryptodome

I am using the pycryptodome package to implement a cryptographic voting protocol. I am using the Nist256 curve and would like to create a second generator, independent of the default generator i.e. not related to it by scalar multiplication. The…
0
votes
0 answers

Python Cryptography. Question related to pycryptodome library: 'SHA256_init' not found in library

I'm using pycryptodome library to do hashing. I tried SHA using pycryptodome. from Crypto.Hash import SHA256 mess = b'hello' h = SHA256.new(mess) print(h.hexdigest()) This is the code I'm using but is giving me errors. Traceback (most recent call…
Krishna
  • 1
  • 1
0
votes
2 answers

How can I decode a 128 byte string that has been RSA encoded with a private key. It follows the PKCS#7 standard, but without the hashing mechanism

I have a 128 byte string (in hex) that is encoded with a private key. I understand this is done to ensure that only those people with the private key can create this string (that is then added to a 2D barcode). I have a public certificate in X509…
Mr_P
  • 1
  • 1
0
votes
1 answer

ERROR: Could not build wheels for pycrypto, which is required to install pyproject.toml-based projects

im install pycryto in python 3.11.3 and that was the error(cryptography is installed successfully): Collecting pycrypto Using cached pycrypto-2.6.1.tar.gz (446 kB) Preparing metadata (setup.py) ... done Building wheels for collected packages:…
0
votes
0 answers

How to link Cryptodome with pycryptodome?

Im using windows 11, with python 3.10 installed I have made sure to install pycryptodomex throught command: pip3 install pycryptodomex but I still have this error File "C:\Users\theac\mtkclient\mtkclient\Library\hwcrypto_dxcc.py", line 10, in…
0
votes
0 answers

pycryptodome install - error: subprocess-exited-with-error

While trying to install pycryptodome for jose jwt library, I encountered this error. I quite new. I have tried to specify which pip I was using. In this case, it is my virtual environment python pip.
0
votes
1 answer

AES Key (Byte array) to string on Python

Ok, I'm a programmer on C#, I used to have a program that transform a byte array from the AES key and IV to a base64 string and write this on a file. But I'm with a big problem, I need to made te same thing on Python, and the Python works very bad…
DazzRick
  • 85
  • 7
0
votes
0 answers

ModuleNotFoundError: No module named 'Crypto.PublicKey'

I get the error: from Crypto.PublicKey import RSA ModuleNotFoundError: No module named 'Crypto.PublicKey' when i'm trying to host a web app using django. enter image description here clearly, PublicKey exists in my virtual environment and RSA is…
kilgaz
  • 1
  • 1
0
votes
0 answers

Cannot install pyrobase because of pycryptodome

I am trying to install and use pyrebase on pycharm but cant seem to install it through pip as it first gives the error: ERROR: Failed building wheel for pycryptodome Running setup.py clean for pycryptodome Failed to build pycryptodome Installing…
kilgaz
  • 1
  • 1
0
votes
0 answers

Decrypting string in Python encrypted in C# AES 256

Data is being encrypted in C# and send to us, I need to write a Python code to decrypt it. Here is the C# code for encryption: public static string EncryptString(string key, string plainText) { byte[] iv = new byte[16]; …
Niyazi
  • 1
0
votes
0 answers

OSError: Cannot load native module 'Crypto.Hash._SHA256'

I am building an app with a vue.js front end with a FastAPI back end. I was having some backend issues with Python 3.11 (uvicorn getting Internal Server Errors) so have just rolled back to 3.10 following some advice I got. However, I'm now getting…
Sean
  • 494
  • 6
  • 23
0
votes
0 answers

Problem with extracting Private Key from PKCS8 wrapper Blob

I have been facing issues in using a private key created using Java Code in my python code. While generating a Private key on Python works well for X25519 key exchange, same is failing for Java generated keys. Following are my keys: Java Key:…