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

How do I take a Public Key String and turn it into a Pycryptodome key (Python)

I have a public key, however, I'm not sure on how to turn that into a key on Pycryptodome. I've been using this code that I found here keyDER = b64decode(key64) seq = asn1.DerSequence() seq.decode(keyDER) keyPub = RSA.construct((seq[0],…
Nate
  • 51
  • 7
0
votes
1 answer

Skipping elif statement?

Am trying to create a simple encryption/decryption using pycryptodome but keeping getting the following error: ValueError: Error 3 while encrypting in CBC mode after some digging I saw that you get this error if there is not enough data to encrypt,…
0
votes
2 answers

Using Pycryptodome library for python, I am getting a TypeError: Only byte strings can be passed to C code" whenever I try to decrypt

def aes128_decrypt(self, msg): iv = os.urandom(16) aes_obj = AES.new(self.key, AES.MODE_CBC, iv) decrypted_msg = aes_obj.decrypt(msg) return decrypted_msg I am using this to decrypt and msg is being passed in as a bytearray. I am…
user2063496
  • 75
  • 1
  • 1
  • 6
-1
votes
1 answer

Bouncy Castle and CryptoJS vs Pycryptodome and Cryptography - who's right and how to decrypt the data in Python?

Let me explain. I have some data encrypted by Bouncy Caste library (AES 128 CBC). I am able to decompress the data using Crypto.js: var CryptoJS = require('crypto-js') const ivHexString = '4d055a9e07e7db37297dd20cc73c4cc4' const keyHexString =…
Marek Marczak
  • 532
  • 8
  • 14
-1
votes
2 answers

Error in AES Encryption/Decryption via python

We have integrated a API through which I am getting a encrypted data. Now in the docs they have given me a software link to decrypt the data. Here is the website they have recommend me to use to decrypt the received…
Harshit verma
  • 506
  • 3
  • 25
-1
votes
1 answer

How to resolve errors that occur during installation of pycryptodome

Collecting pycryptodome Using cached https://files.pythonhosted.org/packages/b9/05/0e7547c445bbbc96c538d870e6c5c5a69a9fa5df0a9df3e27cb126527196/pycryptodome-3.18.0.tar.gz ERROR: Command errored out with exit status 1: command:…
-1
votes
1 answer

Object type cannot be passed to C code when encrypting file in django

so i want to encrypt file .txt with keyword i was input. but i got error message Object type cannot be passed to C code my problem is with this code: aes = AES.new(key.encode('utf8'), AES.MODE_CTR, counter=ctr) if i add encode to…
-1
votes
1 answer

How to find the right key when decryption is not decodable with PyCryptodome

I am new to cryptology. There is a file.aes that is encrypted using AES with 128-bit key and ECB. I have no clue what format the original file is. I am given a set of keys that I was told one of them will decrypt it correctly. So I wrote a python…
Sara Takaya
  • 298
  • 2
  • 17
-1
votes
1 answer

Finding passphrase from private RSA key

I'm working with pycrpytodomex lib in python3. Here I'm using a passphrase while generating an RSA key: from Cryptodome.PublicKey import RSA def encrypt(pass1): key = RSA.generate(2048) encrypted_key = key.exportKey(passphrase=pass1, pkcs=8,…
Nikhil VJ
  • 5,630
  • 7
  • 34
  • 55
-1
votes
1 answer

Problem with random numbers for RSA.generate from PyCryptodome

I try to use PyCryptodome for producing RSA key with a call to os.urandom to first get som random numbers. I must do some statistical testing and processing on the random data before i generate the RSA keys. I can use a file object to for loading…
-1
votes
1 answer

How to use python to get the same decrypted result like I did using OpenSSL?

For some reason I need to use 3DES, I know it's weak. This is the original unencrypted text file: # cat test.txt This is the test text file. Used for testing the encryption and decryption differences. In order to perform the test, I encrypted a…
-1
votes
2 answers

Getting Exception:TypeError: new() missing 1 required positional argument: 'mode'

I want to use AES encryption to encrypt my data I have done it before but in my laptop the method is not working and giving me same error is there any way to fix it ? Here is the code : from Crypto.Cipher import AES def paddedKey(key): while…
-1
votes
1 answer

Flask-User : Impossible to install flask-user I get an permission error

Hi I 'm trying to install flask-user its seems that it don't want to be installed I used a virtualenv environment and python3.7 flask 1.1.2 I have looking for how to fixe it but I didn't find any solutions , is it someone can help me to fix that, …
Bryan Bouka
  • 55
  • 2
  • 8
-1
votes
1 answer

how do I use this pycrypto code in pycryptodome

how do I use this pycrypto code in pycryptodome: #!/usr/bin/env python from Crypto.Cipher import AES import base64 import os # the block size for the cipher object; must be 16 per FIPS-197 BLOCK_SIZE = 16 # the character used for padding--with a…
S. Raud
  • 3
  • 4
-2
votes
1 answer

PyCryptodome decrypt_and_verify is returning "ValueError: MAC check failed"

I have this Java code byte[] decoded= Base64.getDecoder().decode(str.getBytes(StandardCharsets.UTF_8)); byte[] copyfrom12= Arrays.copyOfRange(decoded, 0, Integer.parseInt("12")); SecretKeySpec secretkeyspec= new…
hanan
  • 532
  • 2
  • 7
  • 23
1 2 3
17
18