Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,14 +35,6 @@ def handle_file_upload(uploaded_file):
|
|
| 35 |
except Exception as e:
|
| 36 |
raise ValueError(f"File upload error: {e}")
|
| 37 |
|
| 38 |
-
def create_download_link(data, filename):
|
| 39 |
-
try:
|
| 40 |
-
b64 = base64.b64encode(data).decode('utf-8')
|
| 41 |
-
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">Download {filename}</a>'
|
| 42 |
-
return href
|
| 43 |
-
except Exception as e:
|
| 44 |
-
raise ValueError(f"Error creating download link: {e}")
|
| 45 |
-
|
| 46 |
st.title("File Encryption and Decryption")
|
| 47 |
|
| 48 |
tabs = st.tabs(["Encrypt", "Decrypt"])
|
|
@@ -55,9 +47,14 @@ with tabs[0]:
|
|
| 55 |
if uploaded_file and encryption_key:
|
| 56 |
try:
|
| 57 |
file_content = handle_file_upload(uploaded_file)
|
| 58 |
-
encrypted_content = encrypt_content(file_content, encryption_key)
|
| 59 |
filename = f"encrypted_{uploaded_file.name}"
|
| 60 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
except Exception as e:
|
| 62 |
st.error(f"An error occurred: {e}")
|
| 63 |
else:
|
|
@@ -73,7 +70,12 @@ with tabs[1]:
|
|
| 73 |
file_content = handle_file_upload(uploaded_file)
|
| 74 |
decrypted_content = decrypt_content(file_content, decryption_key)
|
| 75 |
filename = f"decrypted_{uploaded_file.name}"
|
| 76 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
except Exception as e:
|
| 78 |
st.error(f"An error occurred: {e}")
|
| 79 |
else:
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
raise ValueError(f"File upload error: {e}")
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
st.title("File Encryption and Decryption")
|
| 39 |
|
| 40 |
tabs = st.tabs(["Encrypt", "Decrypt"])
|
|
|
|
| 47 |
if uploaded_file and encryption_key:
|
| 48 |
try:
|
| 49 |
file_content = handle_file_upload(uploaded_file)
|
| 50 |
+
encrypted_content = encrypt_content(file_content, encryption_key).encode('utf-8')
|
| 51 |
filename = f"encrypted_{uploaded_file.name}"
|
| 52 |
+
st.download_button(
|
| 53 |
+
label="Download Encrypted File",
|
| 54 |
+
data=encrypted_content,
|
| 55 |
+
file_name=filename,
|
| 56 |
+
mime="application/octet-stream"
|
| 57 |
+
)
|
| 58 |
except Exception as e:
|
| 59 |
st.error(f"An error occurred: {e}")
|
| 60 |
else:
|
|
|
|
| 70 |
file_content = handle_file_upload(uploaded_file)
|
| 71 |
decrypted_content = decrypt_content(file_content, decryption_key)
|
| 72 |
filename = f"decrypted_{uploaded_file.name}"
|
| 73 |
+
st.download_button(
|
| 74 |
+
label="Download Decrypted File",
|
| 75 |
+
data=decrypted_content,
|
| 76 |
+
file_name=filename,
|
| 77 |
+
mime="application/octet-stream"
|
| 78 |
+
)
|
| 79 |
except Exception as e:
|
| 80 |
st.error(f"An error occurred: {e}")
|
| 81 |
else:
|