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
1
vote
0 answers

Allowing Password to be any length Crypto

I have found the following code to encrypt an excel file in python. However, I noticed that it is only able to use passwords/key of length 16 or 32 characters in order to encrypt the file. I would like the user to be able to use any length passwords…
Jeff Boker
  • 803
  • 1
  • 9
  • 25
1
vote
1 answer

How to decrypt with public key in pyCryptodome (Python 3.7)

I know this question has been asked countless times but either the others that asked it were not clear enough or this is simply impossible (nobody said that though), anyway nobody ever gave a clear answer (maybe with the code). So: I am trying to…
CodEdo
  • 91
  • 2
  • 9
1
vote
1 answer

Using pycryptodome or cryptography in python 3.6. How to achieve this?

Imagine the following message: "This is a message to the signed" I have the need to sign this sample message using "pycryptodome" or "cryptography" in Python 3.6 with the following standards: Format: x.509; Charset: UTF-8; Encoding: Base64; PKCS1…
pmatos
  • 276
  • 4
  • 18
1
vote
0 answers

How to Encrypt a PDF in python using pycryptodome

I am trying to encrypt a PDF file using PyCryptodome and giving some unique ID of the system as key parameter. i.e uuid etc. I want to use AES Encryption along with GCM mode because GCM mode is an Authentic Encryption, as it returns a MAC that is…
Zain Arshad
  • 1,885
  • 1
  • 11
  • 26
1
vote
0 answers

Right way to decrypt RSA session key

I'm using pycryptodomex for RSA encryption, decryption. Im following this article from Cryptodome.PublicKey import RSA from Cryptodome.Cipher import AES, PKCS1_OAEP file_in = open("encrypted_data.bin", "rb") private_key =…
user8838577
1
vote
2 answers

Python RSA sign a string with NONEWithRSA

I am working on a project in which client side code is in Java and they are using NONEWithRSA algorithm to sign and verify a string. I am using PyCryptodome to generate sign for a given string.…
varad
  • 7,309
  • 20
  • 60
  • 112
1
vote
0 answers

Incorrect pad error in Pycryptodome. Encrypted in CryptoJS

I use the following to encrypt in Javascript function encrypt(input, key){ console.log("Input: " + input); var secret_key = CryptoJS.SHA256(key); var iv = CryptoJS.lib.WordArray.random(16); console.log("IV: "+ iv); var body =…
Tarun Maganti
  • 3,076
  • 2
  • 35
  • 64
1
vote
1 answer

How to convert a byte string into a list of tuples?

I'm using the pycryptodome module and its AES functionality to encrypt some data. However I need to generate a key for the AEScipher that I can later retrieve. The project stores all private data (including keys) in the form of an image. Basically…
Chase
  • 5,315
  • 2
  • 15
  • 41
1
vote
1 answer

Python 2.7, Pycryptodome: Can not verify private key signature at server side due to encoding issues

I am sending data in Json format between two nodes using Python Requests module functionality on the client side and Flask server on the server side. I need to digitally sign a Python 2.7 string "some string" with an RSA private key and verify the…
1
vote
2 answers

issue with RSA encryption with PyCryptodome

I need to fix a client/server interaction based on PyCryptodome. The client generates its RSA keys and sends the public one to a server: n_bin_size = 1024 e = 65537 key = RSA.generate(n_bin_size, None, e) # RsaKey object public_key =…
Oldville
  • 111
  • 6
1
vote
1 answer

Decrypting message with purposefully weak private key hangs indefinitely

I'm having issues when generating a public key from a private key, which has been weakened deliberately, and attempting to encrypt/decrypt a message when using PyCryptoDome. The decrypt just seems to hang indefinitely. Note: obviously this isn't my…
alk
  • 13
  • 2
1
vote
1 answer

ValueError: Ciphertext with incorrect length

I have a problem that reads: "Suppose your RSA public-key factors are p = 6323 and q = 2833, and the public exponent e is 31. Suppose you were sent the Ciphertext 6627708. Write a program that takes the above parameters as input and implements the…
Dylaloo
  • 13
  • 6
1
vote
0 answers

BigQuery - AES_DECRYPT GCM - Failed to decrypt ciphertext using key of length 32

I'm trying to store in BigQuery encrypted data using AES GCM. Data is encrypted using Python's Cryptodome library. This is the code from Cryptodome.Cipher import AES from Cryptodome.Random import get_random_bytes key = get_random_bytes(32) def…
AdrianCR
  • 23
  • 1
  • 4
1
vote
1 answer

Verifying digital signature created by pycryptodome in WEB Crypto API

I am signing SHA512 hash with RSA and save it to file. The hash is the same on both python and javascript, but signature can not be verified. Python code: from Cryptodome.Hash import SHA512 from Cryptodome.PublicKey import RSA from…
1
vote
0 answers

Different RSA Signing between pycryptodome and cryptography

When im trying some crypto library rsa signing in python, I noticed that the signature generated between pycryptodome and cryptography are different. Here are my code: pycryptodome import base64 from Crypto.Hash import SHA1 from Crypto.PublicKey…
Ivan Kara
  • 129
  • 4
  • 12