我正在尝试从https://pycryptodome.readthedocs.io/en/latest/src/examples.html中更改一个正式的示例
并适应我正在做的一个小小的加密项目:
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) ]在我的示例文件中,encrypted_data.bin (file_in = open("encrypted_data.bin","rb"))将是一个字符串变量,而不是文件。
如何在下面的循环中使用字符串变量来代替file_in?
enc_session_key, nonce, tag, ciphertext = \
[ **file_in.read(x)** for x in (private_key.size_in_bytes(), 16, 16, -1) ]发布于 2022-10-14 21:48:37
只需将文件读取命令替换为字符串即可。例如:
from Crypto.PublicKey import RSA
from Crypto.Cipher import AES, PKCS1_OAEP
encrypted_data = "my_data_str"
private_key = RSA.import_key("my_private_key_str")
enc_session_key, nonce, tag, ciphertext = \
[ encrypted_data for x in (private_key.size_in_bytes(), 16, 16, -1) ]https://stackoverflow.com/questions/74075104
复制相似问题