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

Error decoding ciphertext with RSA using pycryptodome

I'm using pycryptodome to encrypt a text in this way: def encrypt_with_rsa(plain_text): #First Public Key Encryption cipher_pub_obj = PKCS1_OAEP.new(RSA.importKey(my_public_key)) #encrypt _secret_byte_obj =…
Will
  • 49
  • 8
0
votes
2 answers

unable to import pycryptodome in django

I have created a django-project called dp1 and inside that I have made a djano-app called da1. I am working on Windows inside a virtual env named testing. da1\views.py from django.shortcuts import render # Create your views here. from…
0
votes
1 answer

PyCryptoDome AES CBC documentation code gives different output

I am using the code presented in the documentation of the PyCryptoDome AES CBC documentation. import json from base64 import b64encode from Crypto.Cipher import AES from Crypto.Util.Padding import pad from Crypto.Random import get_random_bytes data…
BCT
  • 193
  • 8
0
votes
2 answers

PyCryptodome AES, 'EcbMode' object has no attribute 'encrypt_and_digest'

I am using Pycharm Text Editor and PyCryptodome Library for encryption of message using Advanced Encryption Standard (AES). It is also one of the majorly used Symmetric Encryption Algorithm. My code of AES Encryption was stated below: from…
Terence Lyu
  • 319
  • 1
  • 3
  • 13
0
votes
1 answer

AES won't decrypt properly

So I am using pycryptodome to encrypt a message using a secret key with AES. I want to then, as a test, decrypt the encrypted message using AES with the same secret key. I have done that here, but the result of the decrypted message is not the…
Jason Garvey
  • 39
  • 1
  • 5
0
votes
1 answer

Building Wheel for pycryptodome

I'm installing some packages from an inherited requirements.txt file and it errors out. I've drilled down to the specific package and it's pycryptodome. I can run this without issue: pip install pycryptodome But I need a non-current version for…
Robert Riley
  • 389
  • 1
  • 7
  • 31
0
votes
0 answers

ValueError: not enough values to unpack (expected 4, got 2)

from Crypto.PublicKey import RSA from Crypto.Cipher import AES, PKCS1_OAEP file_in = open("encrypted_data.bin", "rb") private_key = RSA.import_key(open("private.pem").read()) enc_session_key, nonce, tag, ciphertext = [ file_in.read(x) for x in…
Ruch
  • 13
  • 2
0
votes
1 answer

List and x in python?

This code is used to encrypt random input using RSA. I understand this line will write the output into a new file but can't grasp the theory of using x and list ([]) in the code. cipher_aes = AES.new(session_key, AES.MODE_EAX) ciphertext, tag =…
Ruch
  • 13
  • 2
0
votes
0 answers

Unable to install pycryptodome-3.3.1.tar.gz

I'm trying to install pycryptodome-3.3.1.tar.gz on my Windows 10 machine using the package in the link: https://pypi.org/project/pycryptodome/3.3.1/#files My python version is 3.9 and I use cmd to install python packages Currently, I have…
0
votes
0 answers

How to Convert Bytearray to Plaintext?

I am trying to convert bytes to plaintext.I tried .decode() with utf-8,utf-16. But I could not get the required text. cipher = AES.new(KEY, AES.MODE_CBC,INIT_VECTOR) decrypted_text = cipher.decrypt(cipher_text) print("Decrypted…
Max
  • 1
  • 3
0
votes
1 answer

Pycryptodome: ImportError: DLL load failed while importing _AES: %1 is not a valid Win32 application

I have this problem when I try to import Pycryptodome. Traceback (most recent call last): File "C:\Users\me\Documents\Python\Python 3.8\file.pyw", line 17, in from Crypto.Cipher import AES File…
0
votes
1 answer

Why can't I import the Crypto module in python even with pycryptodome installed?

I have run all commands in the terminal to clear any previous forms of crypto, but after I ran "pip3 install pycryptodome" and it successfully installed, I still cannot import the "Crypto.Cipher" module. Can anyone help?
0
votes
0 answers

Printing SHA256 digest result in Python using PyCryptodome library

I'm following example from PyCryptodome documentation. https://pycryptodome.readthedocs.io/en/latest/src/hash/sha256.html Somehow, I'm facing error when I execute the script below. I couldn't spot what wrong in the script.
Pi-Turn
  • 137
  • 4
  • 17
0
votes
1 answer

ModuleNotFoundError: No module named 'Crypto', Python 3.9, PyCharm

from Crypto.Cipher import AES ModuleNotFoundError: No module named 'Crypto' I am using PyCharm Community 2020.3 and Python 3.9. This project previously compiled and ran, but I had to replace the computer and re-create my development…
Guy
  • 666
  • 1
  • 10
  • 34
0
votes
2 answers

TypeError: can't concat str to bytes - Python + pycryptodome

I'm receiving a TypeError when trying to encrypt + decrypt a file using pycryptodome. I've looked around but can't find much relevant to pycryptodome regarding this. The error is: Error Image The code I'm using is: from Crypto.PublicKey import…
Keelan
  • 3
  • 3