File size: 593 Bytes
d90493e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
import streamlit as st
from cryptography.fernet import Fernet
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

# Get the ENC_DEC_KEY from the .env file
ENC_DEC_KEY = os.getenv("ENC_DEC_KEY").encode()  # Ensure this is a bytes object

@st.cache_data()
def decrypt_file(file_path):
    fernet = Fernet(ENC_DEC_KEY)

    with open(file_path, "rb") as file:
        encrypted_data = file.read()

    decrypted_data = fernet.decrypt(encrypted_data)
    return decrypted_data.decode()  # Return the decrypted content as a string