数据隐藏界面
(plugin_name, use_compression, use_encryption,
password, encryption_algorithm, max_bits)
| 123 | |
| 124 | |
| 125 | def data_hiding_ui(plugin_name, use_compression, use_encryption, |
| 126 | password, encryption_algorithm, max_bits): |
| 127 | """数据隐藏界面""" |
| 128 | st.header("📦 数据隐藏") |
| 129 | |
| 130 | tab1, tab2 = st.tabs(["嵌入数据", "提取数据"]) |
| 131 | |
| 132 | with tab1: |
| 133 | st.subheader("将数据嵌入到图像中") |
| 134 | |
| 135 | col1, col2 = st.columns(2) |
| 136 | |
| 137 | with col1: |
| 138 | st.write("**封面图像**") |
| 139 | cover_file = st.file_uploader( |
| 140 | "上传封面图像", |
| 141 | type=['png', 'jpg', 'jpeg', 'bmp'], |
| 142 | help="用于隐藏数据的封面图像" |
| 143 | ) |
| 144 | |
| 145 | if cover_file: |
| 146 | # 重置文件指针并读取数据用于预览 |
| 147 | cover_file.seek(0) |
| 148 | cover_image = Image.open(cover_file) |
| 149 | st.image(cover_image, caption="封面图像", width='stretch') |
| 150 | # 重置文件指针,确保后续读取时数据可用 |
| 151 | cover_file.seek(0) |
| 152 | |
| 153 | with col2: |
| 154 | st.write("**消息文件**") |
| 155 | msg_file = st.file_uploader( |
| 156 | "上传要隐藏的消息文件", |
| 157 | type=None, |
| 158 | help="要隐藏在图像中的文件" |
| 159 | ) |
| 160 | |
| 161 | if msg_file: |
| 162 | st.info(f"文件: {msg_file.name}\n大小: {len(msg_file.read())} 字节") |
| 163 | msg_file.seek(0) # 重置文件指针 |
| 164 | |
| 165 | if st.button("嵌入数据", type="primary"): |
| 166 | if not cover_file: |
| 167 | st.error("请上传封面图像") |
| 168 | elif not msg_file: |
| 169 | st.error("请上传消息文件") |
| 170 | else: |
| 171 | try: |
| 172 | with st.spinner("正在嵌入数据..."): |
| 173 | # 获取插件 |
| 174 | plugin = PluginManager.get_plugin_by_name(plugin_name) |
| 175 | if plugin_name in ["LSB", "RandomLSB"]: |
| 176 | from StegaPy.plugin.lsb.lsb_config import LSBConfig |
| 177 | config = LSBConfig( |
| 178 | max_bits_used_per_channel=max_bits, |
| 179 | use_compression=use_compression, |
| 180 | use_encryption=use_encryption, |
| 181 | password=password, |
| 182 | encryption_algorithm=encryption_algorithm |
no test coverage detected