Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
from cryptography.fernet import Fernet
|
|
|
|
|
|
|
|
|
|
| 4 |
import base64
|
| 5 |
from hashlib import blake2b
|
| 6 |
|
|
@@ -16,29 +19,16 @@ def encrypt(mes=None,img=None,document=None):
|
|
| 16 |
key = Fernet.generate_key()
|
| 17 |
key = "potato"
|
| 18 |
key = key.encode()
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
key =
|
| 28 |
-
key_len = len(key)
|
| 29 |
-
print (f"length1:{key_len}")
|
| 30 |
|
| 31 |
-
print (f"The Key is: {key}")
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
#key = Key.fromUtf8(base64Url.encode(key.bytes))
|
| 35 |
-
#base64.urlsafe_b64encode(os.urandom(32))
|
| 36 |
-
key = base64.urlsafe_b64encode(key)
|
| 37 |
-
|
| 38 |
-
key_len = len(key)
|
| 39 |
-
print (f"length2:{key_len}")
|
| 40 |
-
print (f"The Key is: {key}")
|
| 41 |
-
|
| 42 |
fernet = Fernet(key)
|
| 43 |
|
| 44 |
# then use the Fernet class instance
|
|
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
from cryptography.fernet import Fernet
|
| 4 |
+
from cryptography.hazmat.primitives import hashes
|
| 5 |
+
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
| 6 |
+
import os
|
| 7 |
import base64
|
| 8 |
from hashlib import blake2b
|
| 9 |
|
|
|
|
| 19 |
key = Fernet.generate_key()
|
| 20 |
key = "potato"
|
| 21 |
key = key.encode()
|
| 22 |
+
password=key
|
| 23 |
+
salt = os.urandom(16)
|
| 24 |
+
kdf = PBKDF2HMAC(
|
| 25 |
+
algorithm=hashes.SHA256(),
|
| 26 |
+
length=32,
|
| 27 |
+
salt=salt,
|
| 28 |
+
iterations=480000,
|
| 29 |
+
)
|
| 30 |
+
key = base64.urlsafe_b64encode(kdf.derive(password))
|
|
|
|
|
|
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
fernet = Fernet(key)
|
| 33 |
|
| 34 |
# then use the Fernet class instance
|