Created
September 20, 2022 18:32
-
-
Save komodoooo/f904efa9e091f4b7de4a7ba2e29d8400 to your computer and use it in GitHub Desktop.
Just a simple fernet implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64, sys | |
from cryptography.fernet import Fernet | |
from cryptography.hazmat.primitives import hashes | |
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC | |
key = bytes(sys.argv[4], encoding="utf-8") | |
kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32,salt=b'\xd8Y\x1c\xfb\xc0',iterations=2) | |
kys = base64.urlsafe_b64encode(kdf.derive(key)) | |
f = Fernet(kys) | |
def encrypt(text): print(f.encrypt(bytes(text, encoding="utf-8"))) | |
def decrypt(text): print(f.decrypt(bytes(text, encoding="utf-8"))) | |
try: | |
if sys.argv[1].startswith("-e") and sys.argv[3].startswith("-k"): encrypt(sys.argv[2]) | |
elif sys.argv[1].startswith("-d") and sys.argv[3].startswith("-k"): decrypt(sys.argv[2]) | |
except Exception as bruh: print(bruh) | |
#encrypt example: python3 fernet.py -e [string_to_encrypt] -k [key word] | |
#decrypt example: python3 fernet.py -d [encrypted_string] -k [key word] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment