You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
645 B
18 lines
645 B
11 months ago
|
from Crypto.PublicKey import RSA
|
||
|
from Crypto.Cipher import AES, PKCS1_OAEP
|
||
|
|
||
|
file_in = open("Datos_Encriptados.bin", "rb")
|
||
|
|
||
|
private_key = RSA.import_key(open("privada_usuario_A.pem").read())
|
||
|
|
||
|
enc_session_key, nonce, tag, ciphertext = \
|
||
|
[ file_in.read(x) for x in (private_key.size_in_bytes(), 16, 16, -1) ]
|
||
|
|
||
|
# Desencriptar la desión RSA con la clave privada del usuario_A
|
||
|
cipher_rsa = PKCS1_OAEP.new(private_key)
|
||
|
session_key = cipher_rsa.decrypt(enc_session_key)
|
||
|
|
||
|
# Desencptar los datos ocn la sesión AES
|
||
|
cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
|
||
|
data = cipher_aes.decrypt_and_verify(ciphertext, tag)
|
||
|
print(data.decode("utf-8"))
|