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

Python equivalent to java encryption

In my company, we have java class for encrypt/decrypt-ing small strings such as passwords. Running the java code through a debugger, I can get the encrypted string, and the decrypted string. I then feed the encrypted string into my python code, and…
a693673
  • 57
  • 1
  • 1
  • 5
0
votes
0 answers

How do i encrypt and decrypt files with PyCryptodome? (RSA)

I'm trying to encrypt and decrypt a file with PyCryptodome but without success. I can encrypt strings and data just fine but when trying to encrypt files it fails. I have 2 problems, first is that I can't encrypt larger strings. Witch i tried to…
0
votes
2 answers

Generating fingerprint from X509 certificate using Pycryptodome

I'm trying to generate the same SHA1 fingerprint for a X509 certificate using pycryptodome that I get from the openssl command: openssl x509 -noout -fingerprint -sha1 -inform pem -in certificate.crt My certificate is in PEM format on disk However,…
MvdD
  • 22,082
  • 8
  • 65
  • 93
0
votes
0 answers

pycryptodome creating error while in stalling pyrebase

ERROR: Command errored out with exit status 1: 'C:\Python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] =…
0
votes
0 answers

How is RSA encryption/decryption done in Pycryptodome

I am reading the docs for pycryptodome and got confused at over how the is the data encrypted and transmitted to the receiver and then decrypted over there What I understood is over at the sender side, the public key of the sender is used to encrypt…
manuel
  • 23
  • 6
0
votes
1 answer

crypt with AES 256 2 files inside txt

i have a problem, i got 2 txt files inside other txt, the txt is called secrets.txt , the code is the next... import os import random import hashlib import socket from base64 import b64encode, b64decode from Crypto.Cipher import AES from…
zzzzzzd
  • 19
  • 5
0
votes
1 answer

I have this Python code that is supposed to generate a key and i cant execute the program on Linux

I tried to run this code using both Python and Python 3 on my machine, but it has many errors such as: python3 gen.py Output: Traceback (most recent call last): File "/home/kali/Downloads/gen.py", line 1, in from crypto.Cipher import…
0
votes
1 answer

Compute ecies hkdf symetric key with pycryptodome

Context: i'm working on making a python version of paymentmethodtoken from the google tink library to work with gpay messages. For that i use only python and PyCryptodome. With that said i'm currently trying to implement an equivalent of the kem…
Bastien B
  • 1,018
  • 8
  • 25
0
votes
1 answer

Cannot load native module 'Crypto.Cipher._raw_ecb' when using pyinstaller

I am trying to generate an executable from a python script using pyinstaller. For this I am executing the following command: pyinstaller --onefile --paths /path/to/venv/lib/python3.9/site-packages \ --paths…
WayneNani
  • 173
  • 1
  • 9
0
votes
0 answers

No module named crypto.PublicKey after installing cyrptodome through pip3

I am getting an error for the following import statement: from Crypto.PublicKey import RSA I keep on getting the error: no module named crypto.PublicKey. I have already installed pip3 and used it to install the following programs: POS…
0
votes
0 answers

NoneType has no attribute 'n' in RSA OAEP encryption python

In my attempt at making some sort of secure communications based "FTP" system, I encounter an error when my client-side program first attempts at encrypting data, it throws a single error that I see no examples anywhere else. Traceback (most recent…
Endleon
  • 9
  • 2
0
votes
0 answers

What are the possible reasons for pycryptodome decrypt function to fail?

Below is my code: from base64 import b64encode, b64decode from pathlib import Path from Crypto.Cipher import AES from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_v1_5 def decrypt(base64_ciphertext): private_key =…
0
votes
1 answer

Howto encrypt a message in 3des, use mode MODE_ECB , 192 length password, in python

pip install pycryptodome from Crypto.Cipher import DES3 def encrypt_3ds(encrData): key =…
xyyHIT
  • 11
  • 3
0
votes
1 answer

TypeError: Object type cannot be passed to C code using pycryptodome

I have this code, it used to work in Python 3.6 or 3.7 (I don't exactly remember which version) Now I'm trying the same code in Python 3.9.1 and it gives me error. I'm using pycryptodome from base64 import b64encode, b64decode from Crypto.Cipher…
dldamian
  • 63
  • 1
  • 2
  • 6
0
votes
1 answer

How PyCryptodome context chains messages for AES cipher?

TL;DR: How PyCryptodome AES context chains messages? Consider this piece of code: from Crypto.Util.Padding import pad, unpad from Crypto.Cipher import AES # Create AES-128-CBC context; pad message; encrypt x2. cipher = AES.new(b'Sixteen byte key',…
Vlad Havriuk
  • 1,291
  • 17
  • 29