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

What is encoding error i.e utf-8 error while encrypting?

from Cryptodome.Cipher import AES from Cryptodome.Random import get_random_bytes import hashlib import base64 def decrypt(enc, key_hash): # To decrypt data print("\nIn Decryption method\n") unpad = lambda s: s[:-ord(s[-1:])] …
mani varma
  • 31
  • 1
  • 4
0
votes
2 answers

Pycryptodome .verify() not callable

I am learning Python following an online course and I am having trouble with the pycrytodome .verify() method being not callable (as per pylint). I will bold the exact line where the error occurs. I am posting the entire class. Any help would be…
Monjoie11
  • 33
  • 5
0
votes
1 answer

Trying to use PyCryptodome AES ECB decryption with offsets

As a bit of context to this I am converting a java file to python and am on the last operation. I'm at about 200 LOC so it makes it that much more edge of the seat... Anyways, in java the operation is: Cipher cipher =…
Kevin
  • 167
  • 1
  • 12
0
votes
0 answers

Cryptodome AES encrypt and decrypt

I'm struggling to find the issue within the code: I've txt file on my desktop that i want to encrypt, then decrypt. I'm using AES CBC as my encryption method. Assume the file contain the following string: bla bla top secret!! I'm able to encrypt it…
Itay
  • 3
  • 3
0
votes
0 answers

Which is the simplest (fastest and possibly unsecure) reversible fixed-size length-preserving symmetric cryptography?

Security is irrelevant in my use case. However, a low collision probability is a requirement. By low I mean something comparable to the odds of MD5(textA + keyB) = MD5(textC + keyD) for different texts and keys. Text and key have, say, 16 bytes.…
dawid
  • 663
  • 6
  • 12
0
votes
0 answers

Signing and Verifying of Signature using Pycryptodome always fails

Hi I'm using the Pycryptodome package to try and verify signatures of transactions in a Blockchain. My issue is that when trying to add a new transaction, I first create a signature to be passed into a verify transaction method but for some reason…
A.Healy
  • 41
  • 2
  • 8
0
votes
1 answer

Recreating an openssl decrypt command in PyCrypto

I am trying to recreate the second command (decryption) in PyCrypto openssl enc -aes-128-ecb -nosalt -base64 -pass pass:abcde -md sha256 -in test.txt -out out.txt openssl enc -d -aes-128-ecb -nosalt -base64 -pass pass:abcde -md sha256 -in…
John London
  • 1,250
  • 2
  • 14
  • 32
0
votes
1 answer

Unable to encrypt data in python3 properly

Hi i have written a code in python2 with pycrypto to encrypt and decrypt from a string here is the code hex_key_bytes = array.array('B', [0xb8, 0xf4, 0xc9, 0x57, 0x6e, 0x12, 0xdd, 0x0d,0xb6, 0x3e, 0x8f, 0x8f, 0xac, 0x2b, 0x9a, 0x39]); # Python…
0
votes
1 answer

Why does Pycryptodome MAC check fail when encrypting and decrypting JSON files?

I am trying to do encrypt some JSON data with AES-256, using a password hashed with pbkdf2_sha256 as the key. I want to store the data in a file, be able to load it up, decrypt it, alter it, encrypt it, store it, and repeat. I am using the passlib…
Uriah Wardlaw
  • 87
  • 2
  • 7
0
votes
1 answer

Trying to understand Python's AES methods

I wish, using Python3's Crypto.Cipher to use AES in CTR mode. The actual problem is that I have an array of binary digits ( "0/1" in string format ) and that I wish to encrypt/decrypt them using the AES-CTR. After viewing this article I tried to…
ex1led
  • 427
  • 5
  • 21
0
votes
0 answers

Should I generate a new RSA key pair every time a user is going to encrypt a new file?

I'm working on a project in which I'm going to encrypt some files. I already have an AES function implemented, and now I'm implementing an RSA portion. On the AES part, I created a new key every time I was going to encrypt a new file, even if the…
0
votes
1 answer

How to fix Python import error for Crypto.Signature.DSS

I am trying to run the pycryptodome example for DSA. Here is the example code: from Crypto.PublicKey import DSA from Crypto.Signature import DSS from Crypto.Hash import SHA256 # Create a new DSA key key = DSA.generate(2048) f =…
arnobpl
  • 1,126
  • 4
  • 16
  • 32
0
votes
1 answer

Pycryptodome Python3 RSA.importKey blocking/hangs

I am running Python 3.5.2 with the latest version of Pycryptodome. When importing my RSA private key using RSA.importKey there is an infinite hang or block. I've tried to step through the lib and cannot find any reason why. The private key is an RSA…
Harvey
  • 1,320
  • 3
  • 13
  • 33
0
votes
1 answer

Unable to Decrypt a file using Key in Python

I have a video file which I am trying decrypt . The key is stored in a file. For some reasons it's not working and giving me this error "TypeError: Object type cannot be passed to C code" DecryptFile function I wrote takes 3…
0
votes
0 answers

"Ciphering services not available" error with SNMP V3 usage of pysnmp in python v3 virtual environment

I am trying to use pysnmp library with SNMP V3 settings with MD5 Auth protocol and AesCfb128 Priv protocol to obtain details from a switch. I am trying two things. 1. Install pysnmp and all dependency packages (including pycrytpto) in base…
ICK Geek
  • 13
  • 3