funcionando trabalho 4

This commit is contained in:
2023-10-22 17:15:12 -03:00
parent c8799ed37a
commit 83f806b815
6 changed files with 45 additions and 43 deletions
+5 -2
View File
@@ -1,4 +1,5 @@
from Crypto.Cipher import AES
import base64
class AESCipher(object):
def __init__(self, key):
@@ -8,14 +9,16 @@ class AESCipher(object):
def encrypt(self, raw):
cipher = AES.new(self.key, AES.MODE_EAX, nonce=self.nonce)
ciphertext, _ = cipher.encrypt_and_digest(raw.encode())
return ciphertext
return base64.b64encode(ciphertext)
def decrypt(self, enc):
if type(enc) == str:
enc = eval(enc)
enc = base64.b64decode(enc)
cipher = AES.new(self.key, AES.MODE_EAX, nonce=self.nonce)
plaintext = cipher.decrypt(enc)
print('plaintext', type(plaintext), plaintext)
print('plaintext', plaintext.decode())
return plaintext.decode()