-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdescc.py
24 lines (23 loc) · 1004 Bytes
/
descc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def descc_func():
import base64
import os
from cryptography.fernet import Fernet
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
try:
mes = input("Secret Message :")
password = input("Key :")
salt = os.urandom(16)
kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt, iterations=100000, backend=default_backend())
key = kdf.derive(password.encode())
kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt, iterations=100000, backend=default_backend())
kdf.verify(password.encode(), key)
key = base64.urlsafe_b64encode(key)
fernet = Fernet(key)
token = fernet.encrypt(mes.encode())
print("Encrypted :",str(token)[2:-1])
ccc=fernet.decrypt(token)
print("Decrypted :",str(ccc)[2:-1])
except:
print("Wrong Value..!")