0
RSA 키로 파일을 암호화하는 pycryptodome 예제를 사용하려고합니다.PyCryptodome RSA 암호화
from Crypto.PublicKey import RSA
from Crypto.Random import get_random_bytes
from Crypto.Cipher import AES, PKCS1_OAEP
file_out = open("encrypted_data.bin", "wb")
recipient_key = RSA.import_key(open("receiver.pem").read())
session_key = get_random_bytes(16)
# Encrypt the session key with the public RSA key
cipher_rsa = PKCS1_OAEP.new(recipient_key)
file_out.write(cipher_rsa.encrypt(session_key))
# Encrypt the data with the AES session key
cipher_aes = AES.new(session_key, AES.MODE_EAX)
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
[ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]
을 다음과 내가받을 오류가 난이 오류가 pyCrypto있는 버전 문제로 확인되었다 다른 스레드를 발견
AttributeError: module 'Crypto.PublicKey.RSA' has no attribute 'import_key'
하지만 난 노력하고 같이 예입니다 PyCryptodome을 사용하려면 최신 버전이 있어야합니다.
PyCrypto가 아닌 올바른 버전을 사용하고 있는지 어떻게 확인합니까? – jaydoe
'Cipher.version_info' 튜플을 확인할 수 있습니다. PyCryptodome의 버전은 3.0.0 이상입니다. 또는'pycryptodomex'를 설치할 수 있습니다. 이것은 여전히 PyCryptodome이지만'Cryptodome' 패키지 (충돌을 피하기 위해'Crypto' 대신에) 아래에 있습니다. – SquareRootOfTwentyThree