funcionando trabalho 4
This commit is contained in:
+5
-2
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user