Added libs
This commit is contained in:
17
fspn/utils/aes_util.py
Normal file
17
fspn/utils/aes_util.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from Crypto.Cipher import AES
|
||||
|
||||
def encrypt(data:bytes, key:bytes):
|
||||
cipher = AES.new(key, AES.MODE_EAX)
|
||||
nonce = cipher.nonce
|
||||
ciphertext, mac = cipher.encrypt_and_digest(data)
|
||||
return nonce, ciphertext, mac
|
||||
|
||||
def decrypt_and_verify(nonce:bytes, data:bytes, mac:bytes, key:bytes):
|
||||
cipher = AES.new(key, AES.MODE_EAX, nonce=nonce)
|
||||
plaintext = cipher.decrypt(data)
|
||||
try:
|
||||
cipher.verify(mac)
|
||||
except ValueError:
|
||||
return None
|
||||
return plaintext
|
||||
|
||||
Reference in New Issue
Block a user