I am trying to change an official example from https://pycryptodome.readthedocs.io/en/latest/src/examples.html
and adapt to a little encryption project I am working on:
from Crypto.PublicKey import RSA
from Crypto.Cipher import AES, PKCS1_OAEP
file_in = open("encrypted_data.bin", "rb")
private_key = RSA.import_key(open("private.pem").read())
enc_session_key, nonce, tag, ciphertext = \
[ file_in.read(x) for x in (private_key.size_in_bytes(), 16, 16, -1) ]
in my case file from example encrypted_data.bin (file_in = open("encrypted_data.bin", "rb")) will be a string variable rather than file.
How to adapt below loop to use string variable instead file_in ?
enc_session_key, nonce, tag, ciphertext = \
[ **file_in.read(x)** for x in (private_key.size_in_bytes(), 16, 16, -1) ]