Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python fernet

from cryptography.fernet import Fernet
message = "my deep dark secret".encode()

f = Fernet(key)
encrypted = f.encrypt(message)
Comment

Fernet in python

from cryptography.fernet import Fernet

data = "Here is some data I would like to encode!".encode('utf-8')
my_key = Fernet.generate_key() # keep this key safe! DO NOT LOSE IT!
# If you lose your key, any data that you encrypted and didn't decrypt
# will be lost forever. (Unless, of course, you have an excellent memory
# and can remember a 32 character long series of random and 
# cryptographically secure bytes. In which case, you're fine.)

t = Fernet(my_key)
encrypted = t.encrypt(data)
# This will return a series of bytes, so to convert it back to a string:
boring_old_string = encrypted.decode()

# If you wanted to decrypt a message:
decrypted = t.decrypt(encrypted) 
# This will return bytes, so use the method above to make it a string
Comment

PREVIOUS NEXT
Code Example
Python :: python create list with n elements 
Python :: decrease hours in datetime python 
Python :: base64 python decode 
Python :: pretty json python 
Python :: bot ping discord.py 
Python :: find width and height of imported video frame opencv2 
Python :: creating dictionary using the keys 
Python :: find a file in python 
Python :: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable 
Python :: convert xml to dataframe python 
Python :: install hydra python 
Python :: list to dict python 
Python :: numpy apply function to array 
Python :: file handling modes in python 
Python :: python defaultdict example 
Python :: get all files in directory python 
Python :: label encoding 
Python :: multiply all values in column pandas 
Python :: change tensor type pytorch 
Python :: how to append data to csv file in python without replacing the already present text 
Python :: pil image to numpy 
Python :: pip clear download cache 
Python :: look through dict 
Python :: python screen click 
Python :: tkinter radio buttons 
Python :: plt change grid color 
Python :: with urllib.request.urlopen("https:// 
Python :: state_dict() 
Python :: remove special characters from string python 
Python :: kfold cross validation sklearn 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =