-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecryptString.py
More file actions
29 lines (23 loc) · 819 Bytes
/
decryptString.py
File metadata and controls
29 lines (23 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from cryptography.fernet import Fernet
# Generate key / (If key has all ready been generated skip this step)
key = Fernet.generate_key()
file = open("key.key", "wb")
file.write(key)
file.close()
# Read key / Get the key from the file
file = open("key.key", "rb")
key = file.read() # The key will be type 'bytes'
file.close()
# Read encrypted message and save it to variable
file = open("encryptedMessage.byte", "rb")
encrypted_message = file.read() # Also is in bytes
file.close()
# Decrypt the encrypted message
f = Fernet(key)
decrypted_message = f.decrypt(encrypted_message)
# To know that the variable is as byte it with show like this: b'blahblahblah'
# To decode the byte to string
# Decode the encoded message
original_message = decrypted_message.decode()
# Show original message
print(original_message)