fernet_app / app.py
ansine's picture
Upload 5 files
5fbabe4
raw
history blame contribute delete
961 Bytes
import streamlit as st
from cryptography.fernet import Fernet
st.write("""
# fungsi fernet
""")
# we will be encrypting the below string.
input = st.text_input('Masukkan Teks', 'Ansine Krisnawati R. Loba')
# generate a key for encryption 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(input.encode())
st.write('enkripsi :', 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()
st.write('dekripsi :', decMessage)