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
1 answer

I received an error importing PyPDF2 library after I installed it

I am trying to import PyPDF2 after successfully installing its latest version. And python 3.8.1 is also istalled on my enviornment. I get the following error: File /anaconda/envs/us_indust/lib/python3.8/site-packages/Crypto/Cipher/ARC4.py:119 117…
yousef a
  • 1
  • 1
0
votes
0 answers

Python - Detect type of private key (rsa/dsa/ecc)

I have many private keys in a format looking like this: -----BEGIN ENCRYPTED PRIVATE KEY----- ... -----END ENCRYPTED PRIVATE KEY----- I would like to remove the passphrase from these keys using the python PyCryptodome lib. I do know the…
Zulakis
  • 7,859
  • 10
  • 42
  • 67
0
votes
0 answers

Decrypt in python pycryptodome AES CBC mode 256

Followed the example here: https://pycryptodome.readthedocs.io/en/latest/src/cipher/classic.html#cbc-mode Also can decrypt in online encryption/decryption services. My example is not working: import hashlib from base64 import b64encode,…
Robb
  • 45
  • 1
  • 5
0
votes
1 answer

Use Web Crypto API to decrypt ciphertext which was encrypted using the Python pycrytodome library in Django

I am running a django app and I am trying to use a RSA 'challenge' to verify that a user has the correct private key. The keys are generated client side using the js Web Crypto API and the public key is sent to django as a jwk and the private key is…
Randusr
  • 39
  • 6
0
votes
1 answer

How to encrypt a message and sign it using PyCryptodome Python?

I am currently learning the Public Key Infrastructure implementation in Python using the PyCryptodome library, but I was having a hard time undestanding how exactly a digital signature is to be send with a message. I was trying to sign and verify…
0
votes
0 answers

Signing and verifying data using pycryptodome (RSA)

I am trying to make my blockchain model using pycryptodome 3.16.0, but can't understand how to sign and verify a blockchain transaction. As far as I understand first client (f.e. John) sign transaction using his private key. The second client (f.e.…
0
votes
1 answer

Python Incorrect AES key length despite passing the a 32 bytes bytearray

I have a specific AES key that I have to work with which is 10h,10h,10h,"A",10h,10h,10h,"AAA",10h,10h,10h,10h,10h,10h,10h,10h,10h,"A",10h,"A",10h,10h,"AA",10h,"A",10h,"A",10h,"A" I have to use this key to encrypt a message. In python I covert it to…
snow monster
  • 91
  • 1
  • 11
0
votes
0 answers

Is CBC 128bit encryption vulnerable if I expose a start-of-text pattern?

I'm doing encryption with my program, but I'm worried about exposing an initial layout in the plaintext. As you can see, I intend to encrypt sha256 of the plain text plus the plain text, all together, I will use the sha256 to calculate integrity and…
SimpleMan
  • 1
  • 2
0
votes
1 answer

Data Length Error when Merging PDFs with PyPDF2

I am starting a project that will take specific pages out of each PDF in a folder and merge those pages into a single file. I am getting the error below when building the quoted code about the length of the encryption, and I don't know where I would…
0
votes
0 answers

Verify in OpenSSL C++ a signature generated in PyCryptoDome

I am trying (in vain) to verify, in a C++ program, a signature that has been generated in a Python program. I've got a hunch it comes from the format of the signature, because I need it to be an ASCII string, but I have tried every combination of…
user325962
  • 11
  • 2
0
votes
1 answer

Using pycryptodome to decrypt encrypted data

I'm new to encryption/decryption, but I have sensitive data that I need to store as encrypted data. Our ETL has a built in encryption process which outputs the following { "data":{ "transformation":"AES/GCM/noPadding", …
ToeKnee
  • 35
  • 1
  • 3
0
votes
1 answer

ModuleNotFoundError: No module named 'Crypto' Python Firebase

I know there are similar questions asked but I have read them and couldn't solved my problem I'm trying to import pyrebase; however it gives me these error messages: Traceback (most recent call last): File…
Phy_Mat11
  • 9
  • 1
  • 1
  • 4
0
votes
0 answers

Is there a way to export an AES key from the Python Pycryptodome module?

I have a project for school and it involves cryptography in Python. I need a way to export an AES key from the Pycryptodome module. I have looked at the docs but all I could find was a way to export a RSA key not an AES key. I have the generation,…
Fighter178
  • 303
  • 2
  • 9
0
votes
0 answers

saving data into the same file after decrypting

from Crypto.PublicKey import RSA from Crypto.Cipher import AES, PKCS1_OAEP file_in = open("sensitive.txt", "rb") private_key = RSA.import_key(open("priv_key.pem").read()) enc_session_key, nonce, tag, ciphertext = \ [ file_in.read(x) for x in…
0
votes
1 answer

Pycryptodome official example

I am trying to change an official example from https://pycryptodome.readthedocs.io/en/latest/src/examples.html and adapt to a little encryption project I am working on: from Crypto.PublicKey import RSA from Crypto.Cipher import AES,…