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

How to set the block counter for chacha20-poly1305 in pycryptodome

I am currently trying to decrypt OpenSSH packets, which are encrypted using chacha20-poly1305. Until now I can decrypt the packet length and check the MAC (I am using pycryptodome) but when I try to decrypt the payload it only return garbled…
JustPlayin
  • 89
  • 11
1
vote
2 answers

No Module name Crypto

I am trying to import Crypto in my python program but i got error. i am working on windows. please help. cmd C:\Users\Raw.306498\Desktop>pip3 install --upgrade pycryptodome Requirement already up-to-date: pycryptodome in…
user10989738
  • 81
  • 1
  • 11
1
vote
1 answer

Probles with AES encrypting. cant decrypt with a right key

I'm trying to decrypt encrypdet data. Data was encrypted with AES CBC mode using pycryptodome lib. Have a such error - "ValueError: Incorrect AES key length (256 bytes) import os from Crypto import Random from Crypto.Cipher import AES class…
maribor
  • 31
  • 5
1
vote
1 answer

How to decode IPFS private and public key in DER/PEM format?

how to decode IPFS private and public key in DER/PEM format that can work with the pycryptodome library(for Python 3)? I get the keys from the IPFS configuration file as strings, so I will not explain this process here. What I'm trying to do: import…
Solinnen
  • 330
  • 1
  • 12
1
vote
1 answer

Python cryptography RSASSA PSS signature returns not valid when check with pycrypto APIs

I'm trying to build a wrapper program around Crypto modules of python for testing and generation of test vectors for a hardware implementation. On the hardware RSASSA_PSS with SHA256 data hash and MGF1 SHA1 identifier is used. I get a valid…
1
vote
1 answer

PyCryptodome AES CBC encryption does not give desired output

I'm trying to encrpyt & decrypt a simple text in AES with CBC mode in Python (2.7.14) with Pycryptodome (3.7.0) Here's my code to attempt encryption: from Crypto.Cipher import AES from Crypto.Util import Padding import base64 encryption_key =…
erdimeola
  • 844
  • 8
  • 17
1
vote
2 answers

Using CTR mode in DES algorithm (in python)

I want to use CTR mode in DES algorithm in python by using PyCryptodome package. My code presented at the end of this post. However I got this error: "TypeError: Impossible to create a safe nonce for short block sizes". It is worth to mention that,…
AI_Eng
  • 11
  • 2
1
vote
1 answer

Encrypt Decrypt encoding on Windows Python

I am trying a very basic use case to encrypt and decrypt a sample string. Below is my method. I am using pycryptodome for the encryption. @staticmethod def encryptdecrypt(field): if field is None: return None else: …
1
vote
1 answer

azure aztk installation pycryptodome

When I am installing the requirements for [Spark Aztk][1] there is an error while installing the dependencies for pycryptodome. gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-3.6/src/MD2.o -L/usr/lib64 -lpython3.6m -o…
angeek86
  • 108
  • 5
1
vote
1 answer

Pycryptodome can't decrypt data

Why cipher3 can't decrypt cipher data? cipher2 and cipher3 use same nonce, but cipher3 can't decrypt data Code: >>> from Crypto.Cipher import AES >>> cipher = AES.new(b"M"*16, AES.MODE_EAX) >>> cipher2 = AES.new(b"M"*16, AES.MODE_EAX,…
Tspm1eca
  • 393
  • 1
  • 3
  • 7
1
vote
1 answer

pycryptodome: OverflowError: The counter has wrapped around in CTR mode

I am having difficulty with AES-CTR encryption using pycryptodome on Python 3. Data can be ~1000 bytes but when it gets long enough it breaks. I do not understand what this error supposedly means or how to get around it. from os import urandom from…
ArekBulski
  • 4,520
  • 4
  • 39
  • 61
1
vote
0 answers

Errors while installing Cryptodome

I tried to install this package with pip install pycryptodomex and it all went fine. but when i tried to check the installation with python -m Cryptodome.SelfTest it returned this error: ERROR: test2…
yal
  • 31
  • 10
0
votes
1 answer

Given final block not properly padded. Such issues can arise if a bad key is used during decryption - AES encryption using pycryptodome

I am using the following class to encode and decode, it works without issues when pass the encrypted string directly from the encrypt function to the decrypt function. But if I try to decrypt the encrypted string using online decryption it throws…
0
votes
1 answer

Import "Crypto.Cipher" could not be resolved Pylance (reportMissingImports) in VSCode intel MAC

I've pip installed the ones that i need as I viewed the documentation and other websites. How come it still says that my module is not found? Here are my imports import socket import random import hashlib from Crypto.Cipher import ARC4 #from…
0
votes
1 answer

'Garbage characters" after decrypting string

I've an Android (java) program which uses ChaCha20-Poly1305 to encrypt some strings, and a python script to decrypt the data. Here's the code to encrypt data: byte[] plainText = "This is a sample test".getBytes(StandardCharsets.UTF_8); byte[] key =…
KTB
  • 1,499
  • 6
  • 27
  • 43