iniciando trab 4

This commit is contained in:
2023-10-22 16:56:01 -03:00
parent 8ce9fbd1f0
commit c8799ed37a
7 changed files with 460 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
from Crypto.Cipher import AES
class AESCipher(object):
def __init__(self, key):
self.key = key
self.nonce = b'\xeb\x06\xfa\xa5C{3\x9d\x9dj\x18\xa2V\xe5\xcb\xc2'
def encrypt(self, raw):
cipher = AES.new(self.key, AES.MODE_EAX, nonce=self.nonce)
ciphertext, _ = cipher.encrypt_and_digest(raw.encode())
return ciphertext
def decrypt(self, enc):
if type(enc) == str:
enc = eval(enc)
cipher = AES.new(self.key, AES.MODE_EAX, nonce=self.nonce)
plaintext = cipher.decrypt(enc)
print('plaintext', type(plaintext), plaintext)
return plaintext.decode()