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

Error message when trying to install Cryptodome using setup.py

I am setting up python's cryptodome on a Windows 7 64 bit machine. I am using the setup.py module to achieve this. The reason I am using setup.py instead of pip is because the machine that I am installing this on does not have external internet…
0
votes
0 answers

Get the counter value after decrypt finished

I am trying to decrypt AES-CTR in SSH using the keys generated by the openssh/openssh-portable library. I extracted the keys successfully from memory. Now, after some printfs and research I found out that it seems like the initial counter is…
JustPlayin
  • 89
  • 11
0
votes
1 answer

Can't verify RSA signature with pycryptodome

I'm trying to sign a message in Android, then send the message, signature and public key to a Django server for verification. I'm using pycryptodome on the server to verify, but verification always fails - problem is I have no idea which bit I'm…
0
votes
2 answers

Python Pycryptodome encryption throws "Ciphertext with incorrect length" error

In continuation to my previous pycryptodome question my requirement now got changed to support 90G of data for encryption. So I have done some design changes, de-factoring the encryption code and make them all run in the subprocess. tar zcvf -…
Ibrahim Quraish
  • 3,889
  • 2
  • 31
  • 39
0
votes
0 answers

Correct key exchange procedure for hybrid encryption using Pycryptodome

I'm writing a module that creates a secure communication channel using ZeroMQ sockets and Pycryptodome. The initial handshake between client and server would follow these steps : Both parties send their public RSA key to each other. The server…
0
votes
1 answer

Have an error with AES key after his RSA decryption

I'm trying to realize hybrid cryptosystem with pycryptodome. from Crypto.PublicKey import RSA from Crypto.Cipher import AES from Crypto.Random import get_random_bytes from Crypto.Random.random import getrandbits from Crypto.Cipher import…
maribor
  • 31
  • 5
0
votes
0 answers

Mix net implementation with RSA in python

I'm trying to implement Mixnet in Python. Consider the example in the linked wiki page — A encrypts a message with A's public key and then encrypts the resulting ciphertext along with B's address with M's public key. When I run my code which…
captain
  • 815
  • 14
  • 26
0
votes
1 answer

Checking hash sums with same data => Always 2 different sums

I am working on a Proof-of-Work system in Python. For generating hash value I am using this function from Cryptodome.Hash import SHA256 def blockhash(sender, msg, signature, nonce, timestamp): h = SHA256.new() hash_str = str(sender) +…
Emil Engler
  • 489
  • 5
  • 14
0
votes
1 answer

AES OFB implementation in python with pycryptodome

I am trying to implement the OFB mode of AES encryption using the pycryptodome library and I'm having issues with understanding what input should i give to the cipher. I know that pycryptodome already has OFB implemented but I need to take the plain…
0
votes
1 answer

Tor Stem: public key don't match one in hidden servce descriptor

I am trying to get the public key of a hidden service I created. There are 2 ways, a one from the private key I have, the other is accessing the hidden service descriptor and taking the public key field. I wrote a python script to test both. But,…
CodeLOL
  • 35
  • 5
0
votes
1 answer

Having issues with Teradatasql python

I would like to connect to the Teradata server and I am using the following code: Import teradata Import teradatasql Con=teradata.connect( connection string) I have downloaded the teradatasql whl file and used the following command to install…
ckp
  • 579
  • 2
  • 10
  • 27
0
votes
1 answer

cx_freeze and cryptodome error after compilation

This error appears after compiling my Python 2.7 project with cx_freeze : https://i.stack.imgur.com/xJKuT.jpg I have the impression that the error comes from the package pycryptodome / pycryptodomex which is well installed since everything works…
Antoine
  • 1
  • 1
0
votes
1 answer

Python Pycryptodome AES-GCM encryption code performance improvement

I am having around 19G of data which I am doing tar and then encrypt. I use below code to do the job. from subprocess import call from Crypto.Cipher import AES from Crypto.Random import get_random_bytes import sys cmd =…
Ibrahim Quraish
  • 3,889
  • 2
  • 31
  • 39
0
votes
0 answers

Apache2 with Flask and Pysnmp - OSError: Cannot load native module 'Cryptodome.Cipher._raw_ecb': Trying '_raw_ecb.pyd':

I use the combination of Apache2, mod_wsgi, flask, pysnmp - SNMPv3 on Windows 10 environment. I integrated flask with apache2 using mod_wsgi. Flask application does SNMP related stuffs, for which i use pysnmp module. I use SNMP v3 which does…
Anand
  • 343
  • 1
  • 5
  • 18
0
votes
2 answers

PyCryptoDome Version 3.6.6 raises an TypeError: Object type cannot be passed to C code

A couple o' years ago i created a cryptograph module in python with PyCryptoDome Version 2.6.1. Now with the new PyCryptoDome Version 3.6.6 and Python 3.6 i got a TypeError with the same code. The error is thrown in the "_init_crypter" - method: …
jgsedi
  • 227
  • 4
  • 18