243 questions
0
votes
0
answers
57
views
Unable to generate CMS PKCS#7 file as per OpenSSL CMS expectation
I am trying to implement CMS detached signature for artifacts in Python. The sign operation is being done by private key stored inside AWS KMS service. I have code signing certificate issued by ...
0
votes
0
answers
233
views
AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes' when using ccxt with Binance API
I'm developing a Flask web app that uses the ccxt library to connect to an API. When trying to run my application, I'm encountering this error:
AttributeError: module 'cryptography.hazmat.bindings....
1
vote
1
answer
59
views
Decrypting image fields for Django REST API responses
I am trying to implement a system in which pictures are encrypted on my database, but when they are sent as a response to a user, this data becomes decrypted. Here is how I am encrypting...
def ...
0
votes
0
answers
101
views
Decrypt data encrypted using pgcrypto in a Python application
I am trying move the data encryption/decryption away from the database into the application (python 3.x). This app needs to encrypt/decrypt data that was encrypted using pgcrypto.encrypt method.
Which ...
0
votes
1
answer
71
views
How to decrypt AES Bounty castle encoded zip file in python?
My teammate wrote kotlin code to encrypt zip files from android side using AES BC and I'm trying to decrypt it. But it's not happening. I need to write client side python code to decrypt those files
...
0
votes
0
answers
98
views
Cannot decrypt private ED25519 key generated with cryptography Python module in ssh-keygen
1. Minimal Python code
import os
from stat import S_IRUSR
from stat import S_IWUSR
from cryptography.hazmat.primitives.asymmetric import ed25519
from cryptography.hazmat.primitives.serialization ...
2
votes
1
answer
386
views
Use AES-256 with python's cryptography.fernet.Fernet by changing values of _signing_key and _encryption_key fields
I want to use AES-256 with python's cryptography.fernet.Fernet class. I have generated two keys with Fernet.generate_key() and tried to run the version of the following code (where instead of key1 and ...
1
vote
0
answers
153
views
Verify detached pkcs7/smime signature with python cryptography
I'm looking to replicate the following command in python:
openssl smime -verify -inform der -in sig.rsa -content data.txt -CAfile ca.crt -purpose any
Given that most other python cryptography ...
0
votes
2
answers
91
views
How to calculate BLE SC Pairing Confirm Value for Passkey Entry in Python?
I'm implementing some Bluetooth Low Energy functionalities in Python.
In the pairing process there is a Pairing Confirm Value like specified in Bluetooth Core Specs 5.3 page 1604 and 1562f.
I have the ...
0
votes
1
answer
684
views
ImportError: DLL load failed while importing _rust: The specified procedure could not be found
I have been trying to run a quick start flask app for the first time via PyCharm / VSCode. My pip is fully upgraded to the latest version, and I have installed requirements.txt in my venv, but when I ...
0
votes
1
answer
151
views
Failure verifying a X.509 Certificate although its not been tampered
I am doing an assignment where I have a CA (server) and a client that requests a certificate from the CA, this function works. The certificate is sent via tcp as bytes. The idea is that clients will ...
0
votes
1
answer
49
views
Cannot access member 'bytes' for type 'str' / Member 'bytes' is unknown
I can not seem to transform the master_pwd string into bytes. I do not know if it's been removed or am I missing something.
The code is not done yet but I do not want to go further unless I find out ...
1
vote
1
answer
58
views
Decrypt a Java encrypted file in Python
I use the following to encrypt a file in Java:
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i <...
0
votes
0
answers
2k
views
How can I install the cryptography module on the latest python version (3.13)?
I need to install the cryptography module since it is a dependency for many modules in my python project that I want to migrate to Python 3.13.
I remember that the same problem occured, when I was ...
0
votes
1
answer
498
views
Python cryptography.x509 : Verification of an x509 cert generated by python x509 module which is signed by a CA (not a root) fails
I've written a Python code to generate a cert chain using cryptography library. It involves three certificates: root, intermediate, and leaf. The root is self signed certificate, intermediate cert is ...
0
votes
0
answers
96
views
Are there poor practices in this use of python cryptography package to generate RSA keypair?
Use case: I want to generate no-passphrase 2048-byte RSA keypairs I can use for service accounts to authenticate to Snowflake. I need to generate them programmatically to make key rotation practical.
...
0
votes
0
answers
70
views
Implementing RSA (not for practical use): Is there a limit to what numbers can be computed by Python (OR) Any other programming language?
I was given an assignment at Uni where we were asked to implement RSA on the programming language of our choice. I chose Python to implement it and I did successfully implement it.
However, it works ...
0
votes
0
answers
64
views
Decryption of a file using fernet module in python
def encrypt(self):
if not os.path.exists(self.filename):
raise Exception('File does not exist!')
# Generate a random salt
salt = Fernet.generate_key()
# ...
1
vote
0
answers
138
views
Using python cryptography to differentiate TLS1.3 rsa_pss_rsae_sha256 from TLS1.3 rsa_pss_pss_sha256 certificates
I generated two certificates using openssl cli. The first (if I'm not wrong) should be rsa_pss_rsae_sha256 and the second (dito) should be rsa_pss_pss_sha256.
openssl genpkey -out ca-rsa.key.pem -...
0
votes
0
answers
76
views
cryptography in python: Fernet key must be 32 url-safe base64-encoded bytes
I am trying to make a login interface in a command prompt,
def login():
key_file_path = "etc/keys/key.key"
# Read the key from the file
with open(key_file_path, "rb") ...
1
vote
0
answers
167
views
How to sign an OCSP request using a CloudHSM private key in Python
I am trying to sign my OCSP builder to create a valid OCSP response for client use. However I'm receiving this error when I try to sign my response builder:
'ERROR': "PKCS#11 Error: Unknown ...
0
votes
1
answer
641
views
pkcs12 extract cert and key from pfx file
I'm trying to extract the cert and key from the pfx file, and then write them to the x.key and x.crt files.
I can get the cert and key by the below Python code, my question is how to write them to the ...
2
votes
1
answer
318
views
Reed solomon and mceliece in python
I am using this library to try and make a mceliece encrypter with reed solomon.
My problem is when I try to decrypt, after applying P_inv the decoder does not recognize the coded data and gives me an ...
0
votes
0
answers
64
views
string decryption in python cipher is not working
In my client-server app, I'm trying to encrypt strings, send, receive and decrypt.
Maybe the order of unpadding and decrypting is wrong, or it does have something about deconding from ascii or uft-8, ...
2
votes
2
answers
279
views
How can I read the encryption key generated by cryptography.fernet from a yaml file as a string?
I have a user interface in python (tkinter) that uses cryptography.fernet to encrypt the password of the user and stores it in a yaml file. For password recovery purposes, I also keep the generated ...
0
votes
1
answer
7k
views
Python 3.11 upgrade - lib64/libc.so.6: version `GLIBC_2.28' not found
Python 3.11 upgrade throws error: lib64/libc.so.6: version GLIBC_2.28' not found [ERROR] Runtime.ImportModuleError: Unable to import module 'xxxxx': /lib64/libc.so.6: version GLIBC_2.28' not found (...
0
votes
0
answers
2k
views
How to export a private key / public key into bytes with Python cryptography module?
I tried many combinations of parameters of rsa.RSAPrivateKey.private_bytes but none of them work:
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives....
1
vote
0
answers
19
views
Can someone confirm if my code satisfies these questions?
Use the
crytographic objects (AESCrypto and RSACrypto)
Install necessary cryptographic module(s).
Verify the hash of the supplied part 1 files (publickey.pem, part1.txt.enc, part1.txt.sig)
with their ...
1
vote
0
answers
142
views
Restricted Python in Zope - Unauthorized Error
I have a python script in the Zope (5.8.3) ZMI. When I was running Zope 5.5.1 this worked perfectly but since I upgraded to 5.8.3 and thus updated all the accompanying python modules, I am now getting ...
2
votes
1
answer
1k
views
Compress secp256k1 elliptic curve x, y coordinates strings strings into hex public key
For context
I am using the azurerm_key_vault_key terraform resource to create an secp256k1 key. I can output the X and Y coordinates for this key as strings that look like this (appears to be a base64 ...
1
vote
1
answer
282
views
Python implementation causing Error in decryption of encrypted file encrypted using openssl enc -md md5 -aes-256-cbc
I am trying to convert my current OPENSSL code to python in Azure databricks which decrypts the encrypted file using RANDOM key and uses AES-256-CBC algorithm.
File is shared by source team which is ...
2
votes
0
answers
313
views
Write FALCON public key,private key, and hash to an external file
I use FALCON from liboqs with python wrapper from OQS. I have 2 python files, one for generating the public key, hashes and dump the result to an external file. While the second file will be use for ...
1
vote
1
answer
70
views
cryptography.fernet.InvalidToken error when trying to use a different key to decrypt a cypher with FERNET
So I was basically trying to create a script that would continuously generate keys and hypothetically brute force finding the correct key for the decryption, and running it outputs this:
This is the ...
0
votes
0
answers
398
views
errors in installing cryptography-40.0.2 python (3.11.3) package in an offline environment in Redhat Linux 7.9
When installing the cryptography python package in an offline environment (no internet), it is failing and trying to access github.com
The error is: failed to connect to github.com: Connection timed ...
2
votes
1
answer
1k
views
What is a fernet key exactly?
According to the documentation for the cryptography.fernet module, fernet keys are:
A URL-safe base64-encoded 32-byte key
Yet this doesn't work:
import secrets
from cryptography import fernet
f = ...
1
vote
1
answer
74
views
Update a class method default arg if the class it call by another package
I need to update a kwarg for a class method which is called by another package.
I interact with PyJWT encode much later this calls cryptography load_pem_private_key (https://cryptography.io/en/latest/...
0
votes
1
answer
641
views
'/usr/bin/arm-linux-gnueabihf-gcc' Error while installing cryptography python package
I am getting an error while trying to install cryptography in a python 3.7.3 venv with latest pip(23.0.1). I have Rust version 1.56.1 installed using rustup, and have all other linux packages relevant ...
2
votes
1
answer
4k
views
Crypto-js equivalent function in python
I have a javascript function which encrypt a json using AES cipher from Crypto-Js module. I want a equivalent of this function in python.
encryptAES = function(data1) {
var keyUtf8 = CryptoJS.enc....
1
vote
1
answer
4k
views
Python AWS Lambda in error because of pyjwt[crypto] (cryptography)
I have the following error when i run my AWS lambda under python 3.9 :
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': /lib64/libc.so.6: version `GLIBC_2.28' not found (...
0
votes
0
answers
226
views
Cannot find what is the encoding of the signature obtained by signing with private key
I create a pair of ed25519 keys and then used the cryptography Python library to sign an auth code with the private key:
private_key = serialization.load_ssh_private_key(open('ed25519', 'rb').read(), ...
2
votes
0
answers
106
views
Python's email package from the standard library inserts spurious linebreaks after S/MIME boundaries which seems to break S/MIME signing
I'm trying to use the cryptography library to sign a document.
The following script (working.py) works when it is executed from a directory that contains a private key and a certificate:
#!/usr/bin/...
0
votes
0
answers
2k
views
Failed to install cryptography in python on linux
so I am running a Linux machine with python 3.10 and the latest version of pip.
when I try installing Cryptography using PIP i get a successful installed message with one warning:
sh-5.1$ pip install ...
0
votes
0
answers
250
views
How do I add a chain of trust with x509.CertificateBuilder?
I'm building a certificate with cryptography.x509.CertificateBuilder:
from pathlib import Path
from cryptography import x509
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography....
0
votes
1
answer
324
views
How to identify end-entity certificate in chain/bundle with Python Cryptography?
I am using Python module pefile to extract the Authenticode from a Windows PE file.
pe.parse_data_directories(directories=[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_SECURITY']])
vAddr = pe....
0
votes
1
answer
239
views
Python RSA: multiply crypto message and then decrypt it again raises DecryptionError('Decryption failed')
I want to do something like that :
#Let m be the initial message
c = rsa.encrypt(m)
new_m = rsa.decrypt( Enc(2m))
Now Enc(2m) = 2^e *c mod n so a user that knows c can have Enc(2m) as well.
My ...
1
vote
0
answers
313
views
Python-based program can't find installed packages
I'm trying to run a new version of a program on an old version of Raspbian OS (10 / buster) that requires the python3-cryptography package. The program requires at least Python 3.8 so, I had to ...
1
vote
1
answer
1k
views
'/usr/bin/gcc' failed with exit code 1 while installing cryptography package python on Python:3.7-alpine
Error stack trace
creating build/temp.linux-aarch64-cpython-37/build
#9 13.81 creating build/temp.linux-aarch64-cpython-37/build/temp.linux-aarch64-cpython-37
#9 13.81 gcc -Wno-unused-...
0
votes
1
answer
86
views
Problem "EXCEPTION NOT FOUND" in Cryptography (Python)
CODE
start_time1 = time.time()
ec = EC(a, b, num)
g, _ = ec.at(at)
assert ec.order(g) <= ec.q
# ElGamal enc/dec usage
eg = ElGamal(ec, g)
# mapping value to ec point
# "masking&...
0
votes
1
answer
122
views
simple affine encryption using python problem
I'm a beginner to python I'm actually trying to encrypt a message using basic python
LETTERS = ["A", "B", "C", "D", "E", "F", "G", ...
0
votes
1
answer
1k
views
How to sign a mail with smime with python and the module cryptography?
I want to send a signed mail with smime with the module cryptography. But all my mail programms can't detect the subject if I sign the mail. If I don't sign the mail it shows the subject.
import ...