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

Pycrypto RSA PKCS1 OAEP SHA256 Interoperability with Java

I'm using the following code in Python + Pycryptodome (Pycrypto fork) to encrypt a message using RSA PKCS#1 OAEP SHA256 (RSA/ECB/OAEPWithSHA-256AndMGF1Padding): from Crypto.Cipher import PKCS1_OAEP from Cryptodome.Hash import SHA256 cipher =…
Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
3
votes
1 answer

Unable to decrypt RSA-OAEP message encrypted with PyCryptodome using SubtleCrypto Web Crypto API

On the server side I am using PyCryptodome to encrypt a message with RSA-OAEP (with SHA-256). I'm trying to decrypt the message using SubtleCrypto Web Crypto API on the client side, but it give me a DOMException error without no further details. On…
3
votes
0 answers

Is there any way to get the output of pgp_sym_encrypt of pgcrypto using Pycryptodome?

I have a pandas dataframe where some columns are already encrypted using pgp_sym_encrypt of postgres. The password used in that encryption is known to me and the encryption is done using aes256 algorithm. After some data manipulation, I have added…
MSS
  • 3,306
  • 1
  • 19
  • 50
3
votes
0 answers

AES decryption in python (pycryptodome) gives "Data must be padded to 16 byte boundary in CBC mode"

I have decrypted the string "12345678901234567890123456789012" in C#, using AES The string is 32 bytes and the resulting "array" (see code) is of length 48, so both are even multiples of 16. key is "b14ca5898a4e4133bbce2ea2315a1916" public…
Cowborg
  • 2,645
  • 3
  • 34
  • 51
3
votes
1 answer

How do I install Splunklib for Python 3.7 on Windows?

Splunklib for Python 3.7 fails to install on my Windows machine. Since pycrypto was not ported to Python 3, I've uninstalled it and installed pycrypodome as replacement. Unfortunately, when trying to install splunklib, pip still tries to install…
Chris Chris
  • 352
  • 3
  • 10
3
votes
0 answers

How to encrypt and store data into a database using django and pycrpytodome?

I created a database using django and created a html form to store the data into the database. Now, I want to encrypt using pycryptodome and store the ciphertext into the database. And I want the decrypted plaintext when I display the data from the…
DodgerMac
  • 51
  • 1
  • 5
3
votes
1 answer

How to encrypt data with RSA private key (not normal signing) in Python?

I want to make RSA encryption with private key (not normal signing), but PyCryptodome seems not be able to do it. The reason I need to do it with private key is, I need to get the same results as from a Java program not written by me, which wrongly…
zry98
  • 31
  • 2
  • 3
3
votes
3 answers

Getting Exception: Object type cannot be passed to C code

I install pip install pycryptodome on Python 3.7.2. I'm getting above exception for obj = AES.new(key, AES.MODE_CBC, iv) line. my code is: from Crypto import Random from Crypto.Cipher import AES import random def get_encryption(): try: …
Anil Jagtap
  • 1,740
  • 4
  • 27
  • 44
3
votes
1 answer

PyCrypto Cyphertext incorrect length even with a one char data

I want to encrypt/decrypt a set of data which is contained in a .csv file. I generate my RSA public/private keys with this code : import Crypto from Crypto.PublicKey import RSA key = RSA.generate(2048) k = key.exportKey('PEM') p =…
3
votes
2 answers

PyCryptoDome : AES-256 giving different output with same key & data

The following code produces a different ciphertext every time I execute it, which shouldn't happen since the key & data being passed is same for every execution. from Crypto.Cipher import AES from Crypto.Util.Padding import pad from base64 import…
shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
2
votes
0 answers

how to use hashAlgo=SHA256 in RSA PKCS1_OAEP in python

I have a function using the link below to sign or encrypt for me with the RSA algorithm. [https://stackoverflow.com/questions/75297468/how-to-use-hashalgo-sha256-in-rsa-pkcs1-oaep-encryption-in-pycryptodome] and use this…
Navrang
  • 41
  • 4
2
votes
1 answer

/app/.heroku/python/lib/python3.7/site-packages/Crypto/PublicKey/RSA.py - Invalid syntax error

I am new to Python and Heroku. When I run the python app in heroku, I am getting below error. I tried to run the app locally and it works fine. Can anyone please help me, how to fix this. (myvenv) C:\Users\pc\Desktop\user1\heroku_captsone>heroku run…
2
votes
0 answers

rsa encryption with flask and javascript

I'm trying to encrypt the data twice with rsa public keys, I'm getting the following error in python, Traceback (most recent call last): File "/Users/pbhat1/Documents/dev/registrationdemo/venv/lib/python3.8/site-packages/flask/app.py", line 2447,…
testasker
  • 29
  • 3
2
votes
1 answer

Is it possible to decrypt a base 64 text with a key and AES standard?

I'm working with Python and the Pycryptodome library. I have a string beginning with 951bd9...[and so on]. Let's suppose I have a key"ThisIsARandomText". My question is : could I decrypt that string with an AES algorithm and that key ? I think I…
Julien
  • 699
  • 3
  • 14
  • 30
2
votes
1 answer

Using RSA to encrypt a message in JS and decrypt in Python

I want to encrypt a message using RSA with a provided PEM public key in Javascript, using SubtleCrypto window.crypto.subtle and then decode it with Python (PyCryptodome) in the back-end. However, I get a ValueError: Incorrect decryption.. I'm not…
musava_ribica
  • 476
  • 1
  • 5
  • 18
1
2
3
17 18