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
2 answers

changing the hash digest to big-endian in Python

I am using the following code to create hash for a message: from Crypto.Hash import SHA256 from Crypto.Signature import PKCS1_PSS msg = b'\x15\x00\xea' hash = SHA256.new(msg) ... signer = PKCS1_PSS.new(privKey) signature =…
TJ1
  • 7,578
  • 19
  • 76
  • 119
1
vote
1 answer

Why PyCryptoDome's 3DES algorithm uses 128-bits or 192-bits key instead of 56-bits?

According to Wikipedia, 3DES's cipher uses a 56-bits encryption key to encrypt data; but Pycryptodome's 3DES class uses either 128-bits or 192-bits encryption key. Also both Pycryptodome's AES's and 3DES's encryption speed are same, output is…
Yılmaz Alpaslan
  • 327
  • 3
  • 16
1
vote
1 answer

C# RijndaelManaged vs Python Crypto.Cipher AES + CBC

I've been banging my head against the wall for a couple of days now and was hoping someone could point out the obvious. I am trying to match the RijndaelManaged encryption of C# with that of Python using Crypto.Cipher. Problem: Despite everything…
Sylver11
  • 129
  • 1
  • 8
1
vote
1 answer

Import public key from JSON file to verify instead of .pem file

So i'm using pycryptodome packages and one of my assignment objective is to verify a message if its authentic in P2PKH try: verifier.verify(hash_obj, signature) print("The message is authentic") except ValueError: print("The…
1
vote
0 answers

Crypting in python using hashlib

I have this piece of code import hashlib from Cryptodome.Cipher import AES decryption_key = hashlib.sha256(b"050746" + b"\x00\x00\x00\x03").digest() iv = 16 * b '\x00' aes = AES.new(decryption_key, AES.MODE_CBC, iv) decrypted_nonce =…
Qwetroman
  • 11
  • 3
1
vote
1 answer

What is the openssl AES-CFB-128 command line equivalent to this python snippet?

I have this python snippet which always worked for me: from Crypto.Cipher import AES # pip install pycryptodome import os def aes_cfb(data, key, iv): ctx = AES.new(key, AES.MODE_CFB, iv = iv, segment_size = 128) decrypted =…
Tomay
  • 35
  • 5
1
vote
1 answer

AES GCM returning "ValueError: MAC check failed"

I'm trying to make a password manager and I am using a KDF to make the key and then use AES GCM to encrypt each row in the database. Each row has a different salt used in the key. I have followed the documentation on pycryptodome to encrypt and…
1
vote
1 answer

AES Decryption in Python when IV and Value provided separately

I've got a encrypt/decrypt class setup based on this SO answer. I've tested it and it works fine. It's not working for a new API I'm pulling information from. The new API is built with PHP and is using the following package to encrypt…
Jed
  • 1,823
  • 4
  • 20
  • 52
1
vote
1 answer

trying to convert Java RSA-PSS signature verification code (with SHA256 hash, SHA1 MGF hash) to Python

Here's my Java code, which successfully verifies the signature, as expected. Signature sig = Signature.getInstance("RSASSA-PSS"); PSSParameterSpec pssParams = new PSSParameterSpec( "SHA-256", "MGF1", new MGF1ParameterSpec("SHA-1"), …
neubert
  • 15,947
  • 24
  • 120
  • 212
1
vote
1 answer

Python AES encryption furnishing different result from originating C# code

C# code uses AES to encrypt arrays of bytes. I have written a Python program using PyCryptodome to do the same thing, but the encrypted bytes are always different from the result when I use the C# code, and I made sure to: set the IV to the same…
Guy
  • 666
  • 1
  • 10
  • 34
1
vote
1 answer

Decrypting Python 256 AES with pycryptodome

I have a serial to TCP device which is receiving data via rs232, encrypting that data, then forwarding to a TCP server. The documentation for the device's encryption methodology is borderline nonexistent, only that its 128, 192, or 256 bit AES…
1
vote
1 answer

Convert Pycryptodome ciphertext to Text

from Crypto.Cipher import AES from Crypto.Util.Padding import pad key = b'mysecretpassword' # 16 byte password cipher = AES.new(key, AES.MODE_CBC) plaintext = b'my super secret message to encrypt' ciphertext = cipher.encrypt(pad(plaintext,…
PidePython
  • 61
  • 1
  • 5
1
vote
2 answers

RSA signed data verification not working PyCryptodome

Sorry for the very specific problem, but I am really going crazy here. I am trying to make a module to simply import when I need to sign something or verify a signature but I encountered a problem, the verificator simply returns true wether I enter…
CodEdo
  • 91
  • 2
  • 9
1
vote
1 answer

Python RSA encryption with PKCS1_OAEP/PKCS1_v1_5 fails to decrypt special characters

I am using the following code to encrypt/decrypt only passwords. It works perfectly fine except special characters. As an example Pa$$w0rd returns Pa1705w0rd . Any idea how to fix it ? By the way, I have also tried PKCS1_v1_5, but same result ! def…
Reuben
  • 5,556
  • 10
  • 43
  • 55
1
vote
1 answer

Crypto++ Signing with PKCS1v15 padding with different algorithms

I am wondering if Crypto++ only signs files using SHA (RSASSA_PKCS1v15_SHA_Signer)? I have been using pyCryptodome to do the signing and verifying, but I want to make a C++ application that does the same. In Python, I can sign the files with any of…
Tomas Berger
  • 173
  • 1
  • 3
  • 15