Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python hash and unhash string

from cryptography.fernet import Fernet
 
# we will be encryting the below string.
message = "hello geeks"
 
# generate a key for encryptio and decryption
# You can use fernet to generate
# the key or use random key generator
# here I'm using fernet to generate key
 
key = Fernet.generate_key()
 
# Instance the Fernet class with the key
 
fernet = Fernet(key)
 
# then use the Fernet class instance
# to encrypt the string string must
# be encoded to byte string before encryption
encMessage = fernet.encrypt(message.encode())
 
print("original string: ", message)
print("encrypted string: ", encMessage)
 
# decrypt the encrypted string with the
# Fernet instance of the key,
# that was used for encrypting the string
# encoded byte string is returned by decrypt method,
# so decode it to string with decode methods
decMessage = fernet.decrypt(encMessage).decode()
 
print("decrypted string: ", decMessage)
Comment

PREVIOUS NEXT
Code Example
Python :: to_frame pandas 
Python :: linkedin api with python 
Python :: join 3 dataframes by index python 
Python :: Change one value based on another value in pandas 
Python :: create an empty array numpy 
Python :: python random uuid 
Python :: how to calculate approximate distance with latitude and longitude 
Python :: python bool 
Python :: python split at index 
Python :: python move item in list to another list 
Python :: check if object is array like python 
Python :: python dataframe appendisnt showing 
Python :: python string to tuple 
Python :: coinflip 
Python :: convert price to float pandas 
Python :: sets in python 
Python :: how to test value error in pytest in python 
Python :: To Divide or Not To Divide codechef solution 
Python :: datetime to unix timestamp python 
Python :: max and min int in python 
Python :: python count of values in array 
Python :: python destructure object 
Python :: django custom authentication 
Python :: seaborn histplot python 
Python :: linear regression python code 
Python :: if start and end point is same in range function python 
Python :: give cell format to condition pandas dataframe 
Python :: Delete cell in jupiter notebook 
Python :: from string to flaot python numpy 
Python :: python vars 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =