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

Incorrect decryption RSA pycryptodome

I try to implement RSA in Python with pycryptodome, the encrypt Works fine but the decrypt function no, my code is the following: from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_OAEP from Crypto.Signature import pss from Crypto.Hash…
Doe
  • 21
  • 1
  • 6
2
votes
0 answers

Can't import ChaCha20

I've been trying to use ChaCha20 for some school work but I can't seem to import it. When I run the code I get an error from Crypto.Cipher import ChaCha20 ImportError: cannot import name ChaCha20 I have tried to import other stuff from…
45Yoda
  • 31
  • 6
2
votes
1 answer

RSA Signature Mismatch between NodeJS and Python

I have two short scripts and a (sample) private key that are not producing the same results. secret.key -----BEGIN RSA PRIVATE…
Devin Rodriguez
  • 1,144
  • 1
  • 13
  • 30
2
votes
1 answer

PyCryptodome RSA signature and verification

I am working on a program which transfers data over the internet in python using the socket module. I am now trying to implement encryption using the pycryptodome module. I am using Salsa20 to transfer normal messages and to transfer the Salsa20 key…
purple_dot
  • 106
  • 2
  • 9
2
votes
1 answer

Python: Cryptodomex not working with DSA verification

I tried to verify the signature of a file by DSA encryption. I am using Pyton 3.6 and pycryptodomex version 3.4.7. Unhappily the documentation code seems to be outdated (was trying to get a simple example working): from Crypto.PublicKey import DSA …
flo_type
  • 21
  • 2
2
votes
4 answers

How to build executable with pyinstaller that uses pycryptodome?

I'm trying to build the following script that uses pycryptodome: # based on this example http://www.codekoala.com/posts/aes-encryption-python-using-pycrypto/#comment-25921785 from Crypto.Cipher import AES from Crypto import Random import…
Pablo
  • 983
  • 10
  • 24
1
vote
1 answer

Python Encryption - Reproducing Error: Data must be padded to 16 byte boundary in CBC mode

I'm having trouble reproducing the following error; Data must be padded to 16 byte boundary in CBC mode When I encrypt my data I use the following padding; BS = 16 pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) and the encryption…
Kakedis
  • 172
  • 8
1
vote
2 answers

AES encryptions/decryptions differs between Python and C#?

i am using AES encryption/decryption in Python3 using the pip pycryptodome package on Linux (Debian, ubuntu). now i needed to implement the same program for Windows by using C#. but the encryption results differs between the two platforms…
1
vote
2 answers

AES encryption and padding across multiple blocks

I am encrypting a large (100GB+) file with Python using PyCryptodome using AES-256 in CBC mode. Rather than read the entire file into memory and encrypt it in one fell swoop, I would like to read the input file a 'chunk' at a time and append to the…
Nevo
  • 752
  • 2
  • 9
  • 22
1
vote
1 answer

Decryption using public key in RSA algorithm in python

I am making a license check where I will be encrypting the string text with private key and decrypting it with the public key, I know that it is not the standard way of decryption but I am trying to build in reverse manner for my project, the…
1
vote
1 answer

pycryptodome & AES CBC : failing to decrypt a string

I'm trying to implement a simple encryption-decryption script with pycryptodome and AES-CBC, that is: no iv, no padding, therefore the string to encrypt is stripped do 16 characters key is not random and is a fixed string. However I fail by…
Fabrice Jaouën
  • 180
  • 1
  • 9
1
vote
0 answers

How to validate a RSA public and private key pair in Python

I generated an RSA public and private key pair using the pycryptodome module and returned the private key to the user. Now, for fetching some specific data, I need to validate the public and private key pair. I have both of them in bytes…
Devansh Singh
  • 134
  • 1
  • 10
1
vote
1 answer

Shared key generation from EC with pycryptodome

I'm curently working on a project were i need to compute an hkdf symetric key. To do that i need to generate a shared secret from the private key and an ephemeral public key. For the rest of my work i did use pycryptodome but i can't find in the doc…
1
vote
1 answer

How can I convert this Java encryption code to python

I was trying to convert a java code to python. tried to use pycryptodome library for the purpose. This is java code: try { String data= "shouldEncryptDATA"; String bas64ed= ""; int len12 = Integer.parseInt("12"); byte[] randomparam=…
hanan
  • 532
  • 2
  • 7
  • 23
1
vote
0 answers

Object type cannot be passed to C code CCAvenue payment gateway interation pycryptodome::3.10.1

I want to integrate CCAvenue payment gateway into my website, for that purpose I have to send all the requirements such as Merchant ID, working key etc in encrypted form to their page for payment. For encryption I am using pycryptodome==3.10.1. This…