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

Why do I have to hexlify before decoding into ascii?

So I've been trying to get better acquainted with crypto using python (specifically pycryptodome) and I've come across an interesting issue trying to decode a byte string into ascii. Please see code below: from Crypto.Signature import…
DGav
  • 271
  • 3
  • 14
0
votes
0 answers

Pycryptodome: AES CBC mode Error 65537

I have to decrypt Data with AES in CBC Mode and Zero-Byte-Padding. Heres my Code (similar to the one in the Documentation): from Cryptodome.Cipher import AES from base64 import b64decode from Cryptodome.Util.Padding import unpad key =…
SomeDude
  • 11
  • 4
0
votes
1 answer

Python PyCryptodome Digital Signature Algorithm with DSS

in Python Pycryptodome default example for DSA-DSS Hi guys.I asked this question but , it's not clever , I deleted on my profile and just asking from my friends account. Problem is that .I tried to use public key encryption , signature , verifiying…
Günel Resulova
  • 151
  • 1
  • 10
0
votes
3 answers

Why PyCryptodome RSA public key generation is so slow?

I am using PyCryptodome libray for my cryptography tasks. I want to generate RSA key as shown in example. I have typed this code: from Cryptodome.PublicKey import RSA key = RSA.generate(2048) and it takes forever to execute. (While typing this…
i_rezic
  • 372
  • 1
  • 15
0
votes
1 answer

How to reduce the length of a message encrypted with Hybrid encryption

I was looking for a good encryption scheme to encrypt my message and i founded that the Hybrid encryption is good for large and small messages. but i have a problem with the length of the output cipher message which is large. if the input was…
Ahmed Salama
  • 111
  • 2
  • 6
0
votes
1 answer

Can't decrypt blowfish CTR file with pycryptodome

I'm trying to recover file encrypted with an old pure python implementation of blowfish. the old code relied on a single blofish.py file (Copyright (C) 2002 Michael Gilfix ) The old data are encrypted performing following operations: cipher =…
Prev-I
  • 61
  • 8
0
votes
2 answers

pycryprodome AES CBC mismatch after decryption in Python

my goal is to have a very simple AES 128 CBC scheme which encrypts a plaintext and then decrypts it based on a given key in Python. I'm using pycryptodome framework and I couldnt find any documentation with an example of the AES CBC scheme.…
0
votes
0 answers

Pyinstaller with encryption results in TypeError cannot be passed to C code

I want to compile an exe with encryption (to prevent "casual" decompiling). I am able to compile with Pyinstaller v2.1 in one exe file using a spec file, when I don't use encryption. But, when I add the following line to the .spec file to introduce…
glycoaddict
  • 641
  • 6
  • 19
0
votes
1 answer

Error in Decryption of QR Code using PyCryptodome

I am implementing a python package which can encrypt and decrypt contents of QR code. I made a module named rsa_module.py, which encrypts and decrypts messages, as follows: from Crypto.PublicKey import RSA from Crypto.Random import…
0
votes
1 answer

Error 65537 while instatiating the CBC mode

I have been using the PyCryptoDome library to encrypt some communications between a client and a server. Here is how the protocol goes. The server sends an RSA public key to the client. The client generates an AES key The client encrypts it.…
noname
  • 342
  • 5
  • 14
0
votes
2 answers

Error 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 1: invalid start byte' decoding bytes after decrypting with pycryptodome

My problem is that when I use pycryptodome for decrypting a string in Python 3.6 with the following code: from Crypto.Cipher import AES from Crypto import Random key = "133BBB3212332231" key_bytestring = key.encode("utf-8") iv =…
edusan1213
  • 359
  • 5
  • 15
0
votes
1 answer

Only byte strings can be passed to C code. python paramiko

I have a simple client-server program that uses python Paramiko. The client sends an encrypted string to the server and the server needs to decrypt it to process it. This is the client: def collect_stats(): try: cpu =…
Seif
  • 701
  • 4
  • 13
  • 32
0
votes
1 answer

PyCryptodome RSA encryption

I am trying to use the pycryptodome example of encrypting a file with an RSA key. The example is as follows from Crypto.PublicKey import RSA from Crypto.Random import get_random_bytes from Crypto.Cipher import AES, PKCS1_OAEP file_out =…
0
votes
1 answer

Python 3.6 - JWCrypto error while importing RSA Key

While this question has been asked before and answered at (JWT encrypting payload in python? (JWE)), I can't seem to get JWK working - I have tried importing my plaintext RSA keys and get an error (adding stacktrace below). Can anyone tell me what…
kilokahn
  • 1,136
  • 2
  • 18
  • 38
0
votes
1 answer

NameError while calling module, declaring default values in a class function

I'm trying to understand Public Key encryption so I wrote this little module using PyCryptodome and the RSA/PKCS1_OAEP module on Python 3 to help me along. However, I keep getting an error: NameError: name 'aesenc' is not defined This is a two…
kilokahn
  • 1,136
  • 2
  • 18
  • 38
1 2 3
17
18