yay it works
This commit is contained in:
BIN
fc43dab7-394f-4142-bb04-b003fb2ceb50.room
Normal file
BIN
fc43dab7-394f-4142-bb04-b003fb2ceb50.room
Normal file
Binary file not shown.
BIN
fc43dab7-394f-4142-bb04-b003fb2ceb50.room.ecrypted
Normal file
BIN
fc43dab7-394f-4142-bb04-b003fb2ceb50.room.ecrypted
Normal file
Binary file not shown.
1
fc43dab7-394f-4142-bb04-b003fb2ceb50.room.encrypted
Normal file
1
fc43dab7-394f-4142-bb04-b003fb2ceb50.room.encrypted
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Njdqd3Q=
|
||||||
21
main.py
Normal file
21
main.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import hashlib
|
||||||
|
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
||||||
|
import secrets
|
||||||
|
|
||||||
|
def encrypt_file(file_data:bytes,jwt_token:str):
|
||||||
|
key = hashlib.sha256(jwt_token.encode("utf-8")).digest()
|
||||||
|
|
||||||
|
aes = AESGCM(key)
|
||||||
|
nonce = secrets.token_bytes(12)
|
||||||
|
|
||||||
|
encrypted = aes.encrypt(nonce, file_data, None)
|
||||||
|
|
||||||
|
return encrypted
|
||||||
|
|
||||||
|
with open("fc43dab7-394f-4142-bb04-b003fb2ceb50.room", "rb") as f:
|
||||||
|
file_data = f.read()
|
||||||
|
|
||||||
|
encrypted_file = encrypt_file(file_data, "user_jwt")
|
||||||
|
|
||||||
|
with open("fc43dab7-394f-4142-bb04-b003fb2ceb50.room.ecrypted", "wb") as f:
|
||||||
|
f.write(encrypted_file)
|
||||||
Reference in New Issue
Block a user