I'm currently working on an ecrypting/decrypting program in Python using Fernet. Here's my code so far:
from cryptography.fernet import Fernet
def decrypter():
enc_message = input("Input an encrypted string:\n")
key = input("Input a key:\n")
fernet = Fernet(key)
dec_message = fernet.decrypt(enc_message).decode()
print(dec_message)
def encrypter():
message = input("Input a string to encrypt:\n")
key = Fernet.generate_key()
fernet = Fernet(key)
enc_message = fernet.encrypt(message.encode())
print("")
print("Original string: ", message)
print("")
print("Encrypted string: ", repr(enc_message))
print("")
print("Key: ", repr(key))
print("")
dec_message = fernet.decrypt(enc_message).decode()
print("Decrypted string: ", dec_message)
encrypter()
decrypter()
Eventually I plan on adding more quality-of-life features, but right now the encrypter function asks you for a string to encrypt, generates a key using Fernet, encrypts your string, and then prints your original string, your newly encrypted string, and the encryption key. (This is not the part that needs fixing.)
The idea of the decrypter function is that it takes an encrypted string and key from the encrypter function. It then decrypts the string using the key and prints it.
My problem is that the key is causing an error. I'm not sure if I've coded the decrypter wrong or if I'm just inputting the key in incorrectly.
My apologies if this is an easily solve-able question, I'm new to Python and couldn't really find any answers specifically for this online. Any help is much appreciated!