Python
悠悠
2025年4月18日

Python还能这么用?U盘加密工具保护你的秘密

前言

存u盘里内容(老师)不想让别人知道,那就写个u盘加密工具来守护它把!

何为u盘加密?

加密U盘是指对U盘内容有加解密保护功能的U盘。市面上的加密U盘主要有三类:A.假加密,仅仅是隐藏文件,设个密码,仅仅验证身份,实际存储内容没有任何变化。B.软加密,内置或附带软件,对数据进行加密,一般用AES,也可分加密区及非加密区。C.硬件加密,内置硬件加密,透明加密,无形之中,完成加密,读取时验证,有的具有一些特殊功能,例如将加密应用于硬盘,插上U盘显示明码,拔下显示就是加密信息。

柿子要挑软的捏,那我们就从软加密入手吧。

核心功能概述

1、使用Fernet对称加密(基于AES-128-CBC),常用的对称加密方式。

2、使用SHA-256哈希存储密码,PBKDF2派生加密密钥

3、加密后将原文件删除,解密后恢复原始文件结构,这样可以隐藏源文件。

4、基于Tkinter的简单GUI界面,简单,但是界面不是很美观,后期可以用ttkbootstrap美化下界面。

运行截图

加密前:

image-20250418221625073.png

image-20250418221625073.png

加密后:

image-20250418221721880.png

解密:

image-20250418221754376.png

关键组件分析

1. 密钥管理机制

def hash_password(self, password):
    """对密码进行哈希"""
    return hashlib.sha256(password.encode()).hexdigest()

def derive_key(self, password):
    """从密码派生加密密钥"""
    kdf = PBKDF2HMAC(
        algorithm=hashes.SHA256(),
        length=32,
        salt=self.salt,
        iterations=self.config["encryption_settings"]["key_iterations"],
    )
    key = base64.urlsafe_b64encode(kdf.derive(password.encode()))
    return key
  • 使用PBKDF2密钥派生函数,通过多次迭代(默认100,000次)增强安全性
  • 使用固定盐值(self.salt = b'USBEncryptionSalt123'),简化密钥管理但降低了安全性
  • 密码验证使用SHA-256哈希,存储在配置文件中

2. 文件加密流程

def encrypt_usb(self, password):
    # ...
    # 创建Fernet加密器
    key = self.derive_key(password)
    fernet = Fernet(key)

    # 打开加密数据文件
    with open(self.data_file, 'wb') as data_file:
        # 写入文件数量
        data_file.write(struct.pack("<I", total_files))

        # 加密并写入每个文件
        for i, file_path in enumerate(files_to_encrypt):
            # 读取文件内容
            with open(file_path, 'rb') as f:
                file_data = f.read()

            # 获取相对路径
            rel_path = os.path.relpath(file_path, self.usb_root)
            rel_path_bytes = rel_path.encode('utf-8')

            # 加密文件内容
            encrypted_data = fernet.encrypt(file_data)

            # 写入路径长度、路径和加密数据
            data_file.write(struct.pack("<I", len(rel_path_bytes)))
            data_file.write(rel_path_bytes)
            data_file.write(struct.pack("<Q", len(encrypted_data)))
            data_file.write(encrypted_data)

            # 删除原文件
            os.remove(file_path)
    # ...
  • 所有文件内容被加密并集中存储在一个单一的加密数据文件(.usbenc_data.bin)中
  • 文件结构信息(相对路径)也被保存,以便解密时恢复原始目录结构
  • 使用二进制格式存储,包含文件数量、路径长度、路径、加密数据长度和加密数据

3. 文件解密流程

def decrypt_usb(self, password):
    # ...
    # 创建Fernet解密器
    key = self.derive_key(password)
    fernet = Fernet(key)

    # 打开加密数据文件
    with open(self.data_file, 'rb') as data_file:
        # 读取文件数量
        total_files = struct.unpack("<I", data_file.read(4))[0]

        # 解密并写入每个文件
        for i in range(total_files):
            # 读取路径长度和路径
            path_len = struct.unpack("<I", data_file.read(4))[0]
            rel_path = data_file.read(path_len).decode('utf-8')

            # 读取加密数据长度和数据
            data_len = struct.unpack("<Q", data_file.read(8))[0]
            encrypted_data = data_file.read(data_len)

            # 解密数据
            decrypted_data = fernet.decrypt(encrypted_data)

            # 确保目标目录存在
            file_path = os.path.join(self.usb_root, rel_path)
            os.makedirs(os.path.dirname(file_path), exist_ok=True)

            # 写入解密后的文件
            with open(file_path, 'wb') as f:
                f.write(decrypted_data)
    # ...
  • 从加密数据文件中读取并解析文件结构信息和加密内容
  • 使用相同的密钥解密数据,并按照原始路径恢复文件
  • 解密完成后删除加密数据文件

4. 配置管理

def load_config(self):
    """加载或创建配置文件"""
    default_config = {
        "is_encrypted": False,
        "password_hash": "",
        "last_access": "",
        "encryption_settings": {
            "key_iterations": 100000,
        }
    }

    if os.path.exists(self.config_file):
        try:
            with open(self.config_file, 'r') as f:
                self.config = json.load(f)
        except:
            self.config = default_config
    else:
        self.config = default_config
        self.save_config()
  • 使用JSON格式存储配置信息
  • 跟踪加密状态、密码哈希、上次访问时间和加密设置
  • 配置文件存储在U盘根目录的隐藏文件中(.usbenc_config.json

5. 密码修改机制

def change_password(self):
    # 先验证当前密码
    current_pwd = simpledialog.askstring("验证当前密码", "请输入当前密码:", show="*", parent=self.root)
    # ...
    
    # 如果U盘已加密,需要先解密到临时目录
    temp_dir = None
    if self.config["is_encrypted"]:
        temp_dir = self.decrypt_to_temp(current_pwd)
        # ...
    
    # 更新密码哈希
    self.config["password_hash"] = self.hash_password(new_password)
    self.save_config()
    
    # 如果有临时解密的文件,需要用新密码重新加密
    if temp_dir:
        success = self.encrypt_from_temp(new_password, temp_dir)
        # ...
  • 修改密码时,先验证当前密码
  • 如果U盘已加密,需要先解密到临时目录,再用新密码重新加密
  • 更新配置文件中的密码哈希

6. 线程处理

def encrypt_usb(self, password):
    # ...
    # 在后台线程中执行加密操作
    def encrypt_thread():
        # 加密操作...
    
    # 启动加密线程
    threading.Thread(target=encrypt_thread).start()
  • 使用后台线程处理耗时的加密/解密操作,避免UI冻结
  • 通过进度条向用户展示操作进度
  • 线程完成后通过after方法安全地更新UI

7. 文件过滤机制

# 跳过隐藏文件和目录
dirs[:] = [d for d in dirs if not d.startswith('.')]

for file in files:
    if file.startswith('.'):
        continue

    # 跳过程序自身和配置文件
    file_path = os.path.join(root, file)
    if file_path == os.path.abspath(sys.argv[0]) or \
            file_path == self.config_file or \
            file_path == self.data_file:
        continue
  • 排除隐藏文件和目录(以.开头)
  • 排除程序自身、配置文件和加密数据文件,确保程序正常运行

发布成exe运行文件

pyinstaller -F -w --icon=tt.ico .\u盘加密工具.py

源码

import sys
import time
import json
import struct
import hashlib
import tkinter as tk
from tkinter import messagebox, simpledialog
from cryptography.fernet import Fernet
import threading
import base64
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
import os
import shutil

class USBSelfEncryptApp:
    def __init__(self):
        # 初始化主窗口
        self.root = tk.Tk()
        self.root.title("U盘自加密工具")
        self.root.geometry("400x300")
        self.root.resizable(False, False)

        # 确定U盘根目录
        self.usb_root = os.path.dirname(os.path.abspath(sys.argv[0]))

        # 配置文件路径
        self.config_file = os.path.join(self.usb_root, ".usbenc_config.json")
        self.data_file = os.path.join(self.usb_root, ".usbenc_data.bin")

        # 初始化盐值
        self.salt = b'USBEncryptionSalt123'  # 固定盐值,简化密钥管理

        # 加载或创建配置
        self.load_config()

        # 创建UI
        self.create_ui()

        # 设置关闭窗口事件
        self.root.protocol("WM_DELETE_WINDOW", self.exit_app)

    def load_config(self):
        """加载或创建配置文件"""
        default_config = {
            "is_encrypted": False,
            "password_hash": "",
            "last_access": "",
            "encryption_settings": {
                "key_iterations": 100000,
            }
        }

        if os.path.exists(self.config_file):
            try:
                with open(self.config_file, 'r') as f:
                    self.config = json.load(f)
            except:
                self.config = default_config
        else:
            self.config = default_config
            self.save_config()

    def save_config(self):
        """保存配置文件"""
        with open(self.config_file, 'w') as f:
            json.dump(self.config, f, indent=2)

    def create_ui(self):
        """创建用户界面"""
        # 标题
        title_label = tk.Label(self.root, text="U盘自加密工具", font=("Arial", 16, "bold"))
        title_label.pack(pady=20)

        # 状态显示
        status_text = "状态: U盘已加密" if self.config["is_encrypted"] else "状态: U盘未加密"
        self.status_label = tk.Label(self.root, text=status_text, font=("Arial", 12))
        self.status_label.pack(pady=10)

        # 上次访问时间
        if self.config["last_access"]:
            last_access_label = tk.Label(self.root, text=f"上次访问: {self.config['last_access']}")
            last_access_label.pack(pady=5)

        # 主操作按钮
        button_text = "解锁U盘" if self.config["is_encrypted"] else "加密U盘"
        self.main_button = tk.Button(self.root, text=button_text, width=15, height=2, command=self.main_action)
        self.main_button.pack(pady=20)

        # 修改密码按钮
        if self.config["password_hash"]:  # 只有设置过密码才显示修改密码按钮
            change_pwd_button = tk.Button(self.root, text="修改密码", width=15, command=self.change_password)
            change_pwd_button.pack(pady=10)

        # 底部信息
        info_label = tk.Label(self.root, text="安全提示: 请记住您的密码,密码丢失将无法恢复数据", font=("Arial", 8))
        info_label.pack(side=tk.BOTTOM, pady=10)

    def main_action(self):
        """主按钮动作"""
        if self.config["is_encrypted"]:
            # 解锁U盘
            password = simpledialog.askstring("需要密码", "请输入解锁密码:", show="*", parent=self.root)
            if password:
                # 验证密码
                if self.verify_password(password):
                    self.decrypt_usb(password)
                else:
                    messagebox.showerror("错误", "密码不正确")
        else:
            # 加密U盘
            if self.config["password_hash"]:  # 如果已经设置过密码
                password = simpledialog.askstring("需要密码", "请输入加密密码:", show="*", parent=self.root)
                if password:
                    # 验证密码
                    if self.verify_password(password):
                        self.encrypt_usb(password)
                    else:
                        messagebox.showerror("错误", "密码不正确")
            else:  # 首次设置密码
                self.set_new_password()

    def set_new_password(self):
        """设置新密码"""
        # 创建密码设置对话框
        pwd_dialog = tk.Toplevel(self.root)
        pwd_dialog.title("设置加密密码")
        pwd_dialog.geometry("300x150")
        pwd_dialog.transient(self.root)
        pwd_dialog.grab_set()

        # 密码输入框
        tk.Label(pwd_dialog, text="请设置加密密码:").pack(pady=(10, 5))
        pwd_entry = tk.Entry(pwd_dialog, show="*", width=25)
        pwd_entry.pack()

        # 确认密码输入框
        tk.Label(pwd_dialog, text="请再次输入密码:").pack(pady=(10, 5))
        confirm_entry = tk.Entry(pwd_dialog, show="*", width=25)
        confirm_entry.pack()

        # 确认按钮
        def confirm_password():
            password = pwd_entry.get()
            confirm = confirm_entry.get()

            if not password:
                messagebox.showerror("错误", "密码不能为空", parent=pwd_dialog)
                return

            if password != confirm:
                messagebox.showerror("错误", "两次输入的密码不一致", parent=pwd_dialog)
                return

            # 保存密码哈希
            self.config["password_hash"] = self.hash_password(password)
            self.save_config()

            pwd_dialog.destroy()

            # 执行加密
            self.encrypt_usb(password)

        confirm_button = tk.Button(pwd_dialog, text="确认", command=confirm_password)
        confirm_button.pack(pady=15)

    def change_password(self):
        """修改密码"""
        # 先验证当前密码
        current_pwd = simpledialog.askstring("验证当前密码", "请输入当前密码:", show="*", parent=self.root)
        if not current_pwd:
            return

        if not self.verify_password(current_pwd):
            messagebox.showerror("错误", "当前密码不正确")
            return

        # 如果U盘已加密,需要先解密到临时目录
        temp_dir = None
        if self.config["is_encrypted"]:
            temp_dir = self.decrypt_to_temp(current_pwd)
            if not temp_dir:
                return

        # 创建新密码设置对话框
        pwd_dialog = tk.Toplevel(self.root)
        pwd_dialog.title("设置新密码")
        pwd_dialog.geometry("350x200")
        pwd_dialog.transient(self.root)
        pwd_dialog.grab_set()

        # 密码输入框
        tk.Label(pwd_dialog, text="请设置新密码:").pack(pady=(10, 5))
        pwd_entry = tk.Entry(pwd_dialog, show="*", width=25)
        pwd_entry.pack()

        # 确认密码输入框
        tk.Label(pwd_dialog, text="请再次输入新密码:").pack(pady=(10, 5))
        confirm_entry = tk.Entry(pwd_dialog, show="*", width=25)
        confirm_entry.pack()

        # 确认按钮
        def confirm_new_password():
            new_password = pwd_entry.get()
            confirm = confirm_entry.get()

            if not new_password:
                messagebox.showerror("错误", "密码不能为空", parent=pwd_dialog)
                return

            if new_password != confirm:
                messagebox.showerror("错误", "两次输入的密码不一致", parent=pwd_dialog)
                return

            pwd_dialog.destroy()

            # 更新密码哈希
            self.config["password_hash"] = self.hash_password(new_password)
            self.save_config()

            # 如果有临时解密的文件,需要用新密码重新加密
            if temp_dir:
                success = self.encrypt_from_temp(new_password, temp_dir)
                if success:
                    # 清理临时目录
                    try:
                        shutil.rmtree(temp_dir)
                    except:
                        pass
                    messagebox.showinfo("成功", "密码已成功修改并重新加密")
            else:
                messagebox.showinfo("成功", "密码已成功修改")

        confirm_button = tk.Button(pwd_dialog, text="确认", command=confirm_new_password)
        confirm_button.pack(pady=15)

    def hash_password(self, password):
        """对密码进行哈希"""
        return hashlib.sha256(password.encode()).hexdigest()

    def verify_password(self, password):
        """验证密码是否正确"""
        return self.hash_password(password) == self.config["password_hash"]

    def derive_key(self, password):
        """从密码派生加密密钥"""
        kdf = PBKDF2HMAC(
            algorithm=hashes.SHA256(),
            length=32,
            salt=self.salt,
            iterations=self.config["encryption_settings"]["key_iterations"],
        )
        key = base64.urlsafe_b64encode(kdf.derive(password.encode()))
        return key

    def encrypt_usb(self, password):
        """加密U盘内容"""
        # 创建进度窗口
        progress_window = tk.Toplevel(self.root)
        progress_window.title("加密进度")
        progress_window.geometry("300x100")
        progress_window.transient(self.root)
        progress_window.grab_set()

        # 进度条
        progress_label = tk.Label(progress_window, text="正在加密U盘内容...")
        progress_label.pack(pady=10)
        progress_bar = tk.Canvas(progress_window, width=250, height=20, bg="white")
        progress_bar.pack(pady=10)

        # 在后台线程中执行加密操作
        def encrypt_thread():
            try:
                # 获取要加密的文件列表
                files_to_encrypt = []
                for root, dirs, files in os.walk(self.usb_root):
                    # 跳过隐藏文件和目录
                    dirs[:] = [d for d in dirs if not d.startswith('.')]

                    for file in files:
                        if file.startswith('.'):
                            continue

                        # 跳过程序自身和配置文件
                        file_path = os.path.join(root, file)
                        if file_path == os.path.abspath(sys.argv[0]) or \
                                file_path == self.config_file or \
                                file_path == self.data_file:
                            continue

                        files_to_encrypt.append(file_path)

                total_files = len(files_to_encrypt)
                if total_files == 0:
                    progress_window.after(0, progress_window.destroy)
                    messagebox.showinfo("完成", "没有需要加密的文件")
                    return

                # 创建Fernet加密器
                key = self.derive_key(password)
                fernet = Fernet(key)

                # 打开加密数据文件
                with open(self.data_file, 'wb') as data_file:
                    # 写入文件数量
                    data_file.write(struct.pack("<I", total_files))

                    # 加密并写入每个文件
                    for i, file_path in enumerate(files_to_encrypt):
                        try:
                            # 读取文件内容
                            with open(file_path, 'rb') as f:
                                file_data = f.read()

                            # 获取相对路径
                            rel_path = os.path.relpath(file_path, self.usb_root)
                            rel_path_bytes = rel_path.encode('utf-8')

                            # 加密文件内容
                            encrypted_data = fernet.encrypt(file_data)

                            # 写入路径长度、路径和加密数据
                            data_file.write(struct.pack("<I", len(rel_path_bytes)))
                            data_file.write(rel_path_bytes)
                            data_file.write(struct.pack("<Q", len(encrypted_data)))
                            data_file.write(encrypted_data)

                            # 删除原文件
                            os.remove(file_path)

                            # 更新进度条
                            progress = (i + 1) / total_files
                            progress_bar.delete("all")
                            progress_bar.create_rectangle(0, 0, 250 * progress, 20, fill="green", outline="")
                            progress_label.config(text=f"正在加密: {i + 1}/{total_files}")

                        except Exception as e:
                            print(f"加密文件 {file_path} 时出错: {str(e)}")

                # 更新配置
                self.config["is_encrypted"] = True
                self.config["last_access"] = time.strftime("%Y-%m-%d %H:%M:%S")
                self.save_config()

                # 更新UI
                self.status_label.config(text="状态: U盘已加密")
                self.main_button.config(text="解锁U盘")

                # 关闭进度窗口并显示成功消息
                progress_window.after(500, progress_window.destroy)
                messagebox.showinfo("完成", f"已成功加密 {total_files} 个文件")

            except Exception as e:
                progress_window.after(0, progress_window.destroy)
                messagebox.showerror("错误", f"加密过程中出错: {str(e)}")

        # 启动加密线程
        threading.Thread(target=encrypt_thread).start()

    def decrypt_usb(self, password):
        """解密U盘内容"""
        # 创建进度窗口
        progress_window = tk.Toplevel(self.root)
        progress_window.title("解密进度")
        progress_window.geometry("300x100")
        progress_window.transient(self.root)
        progress_window.grab_set()

        # 进度条
        progress_label = tk.Label(progress_window, text="正在解密U盘内容...")
        progress_label.pack(pady=10)
        progress_bar = tk.Canvas(progress_window, width=250, height=20, bg="white")
        progress_bar.pack(pady=10)

        # 在后台线程中执行解密操作
        def decrypt_thread():
            try:
                # 检查加密数据文件是否存在
                if not os.path.exists(self.data_file):
                    progress_window.after(0, progress_window.destroy)
                    messagebox.showerror("错误", "找不到加密数据文件")
                    return

                # 创建Fernet解密器
                key = self.derive_key(password)
                fernet = Fernet(key)

                # 打开加密数据文件
                with open(self.data_file, 'rb') as data_file:
                    # 读取文件数量
                    total_files = struct.unpack("<I", data_file.read(4))[0]

                    # 解密并写入每个文件
                    for i in range(total_files):
                        try:
                            # 读取路径长度和路径
                            path_len = struct.unpack("<I", data_file.read(4))[0]
                            rel_path = data_file.read(path_len).decode('utf-8')

                            # 读取加密数据长度和数据
                            data_len = struct.unpack("<Q", data_file.read(8))[0]
                            encrypted_data = data_file.read(data_len)

                            # 解密数据
                            decrypted_data = fernet.decrypt(encrypted_data)

                            # 确保目标目录存在
                            file_path = os.path.join(self.usb_root, rel_path)
                            os.makedirs(os.path.dirname(file_path), exist_ok=True)

                            # 写入解密后的文件
                            with open(file_path, 'wb') as f:
                                f.write(decrypted_data)

                            # 更新进度条
                            progress = (i + 1) / total_files
                            progress_bar.delete("all")
                            progress_bar.create_rectangle(0, 0, 250 * progress, 20, fill="green", outline="")
                            progress_label.config(text=f"正在解密: {i + 1}/{total_files}")

                        except Exception as e:
                            print(f"解密文件 {rel_path} 时出错: {str(e)}")

                # 删除加密数据文件
                os.remove(self.data_file)

                # 更新配置
                self.config["is_encrypted"] = False
                self.config["last_access"] = time.strftime("%Y-%m-%d %H:%M:%S")
                self.save_config()

                # 更新UI
                self.status_label.config(text="状态: U盘未加密")
                self.main_button.config(text="加密U盘")

                # 关闭进度窗口并显示成功消息
                progress_window.after(500, progress_window.destroy)
                messagebox.showinfo("完成", f"已成功解密 {total_files} 个文件")

            except Exception as e:
                progress_window.after(0, progress_window.destroy)
                messagebox.showerror("错误", f"解密过程中出错: {str(e)}")

        # 启动解密线程
        threading.Thread(target=decrypt_thread).start()

    def decrypt_to_temp(self, password):
        """解密到临时目录(用于修改密码)"""
        try:
            # 创建临时目录
            temp_dir = os.path.join(self.usb_root, ".temp_decrypt_" + str(int(time.time())))
            os.makedirs(temp_dir, exist_ok=True)

            # 检查加密数据文件是否存在
            if not os.path.exists(self.data_file):
                messagebox.showerror("错误", "找不到加密数据文件")
                return None

                # 创建Fernet解密器
                key = self.derive_key(password)
                fernet = Fernet(key)

                # 打开加密数据文件
                with open(self.data_file, 'rb') as data_file:
                    # 读取文件数量
                    total_files = struct.unpack("<I", data_file.read(4))[0]

                    # 解密并写入每个文件到临时目录
                    for i in range(total_files):
                        try:
                            # 读取路径长度和路径
                            path_len = struct.unpack("<I", data_file.read(4))[0]
                            rel_path = data_file.read(path_len).decode('utf-8')

                            # 读取加密数据长度和数据
                            data_len = struct.unpack("<Q", data_file.read(8))[0]
                            encrypted_data = data_file.read(data_len)

                            # 解密数据
                            decrypted_data = fernet.decrypt(encrypted_data)

                            # 确保目标目录存在
                            temp_file_path = os.path.join(temp_dir, rel_path)
                            os.makedirs(os.path.dirname(temp_file_path), exist_ok=True)

                            # 写入解密后的文件
                            with open(temp_file_path, 'wb') as f:
                                f.write(decrypted_data)

                        except Exception as e:
                            print(f"解密文件 {rel_path} 到临时目录时出错: {str(e)}")

                return temp_dir

        except Exception as e:
            messagebox.showerror("错误", f"解密到临时目录时出错: {str(e)}")
            return None

    def encrypt_from_temp(self, password, temp_dir):
        """从临时目录重新加密(用于修改密码)"""
        try:
            # 创建Fernet加密器
            key = self.derive_key(password)
            fernet = Fernet(key)

            # 获取要加密的文件列表
            files_to_encrypt = []
            for root, dirs, files in os.walk(temp_dir):
                for file in files:
                    file_path = os.path.join(root, file)
                    files_to_encrypt.append(file_path)

            total_files = len(files_to_encrypt)
            if total_files == 0:
                return True

            # 打开加密数据文件
            with open(self.data_file, 'wb') as data_file:
                # 写入文件数量
                data_file.write(struct.pack("<I", total_files))

                # 加密并写入每个文件
                for file_path in files_to_encrypt:
                    try:
                        # 读取文件内容
                        with open(file_path, 'rb') as f:
                            file_data = f.read()

                        # 获取相对路径
                        rel_path = os.path.relpath(file_path, temp_dir)
                        rel_path_bytes = rel_path.encode('utf-8')

                        # 加密文件内容
                        encrypted_data = fernet.encrypt(file_data)

                        # 写入路径长度、路径和加密数据
                        data_file.write(struct.pack("<I", len(rel_path_bytes)))
                        data_file.write(rel_path_bytes)
                        data_file.write(struct.pack("<Q", len(encrypted_data)))
                        data_file.write(encrypted_data)

                    except Exception as e:
                        print(f"从临时目录加密文件 {file_path} 时出错: {str(e)}")

            return True

        except Exception as e:
            messagebox.showerror("错误", f"从临时目录重新加密时出错: {str(e)}")
            return False

    def exit_app(self):
        """退出应用程序"""
        if messagebox.askyesno("确认退出", "确定要退出吗?"):
            self.root.destroy()

    def run(self):
        """运行应用程序"""
        self.root.mainloop()


def main():
    app = USBSelfEncryptApp()
    app.run()

if __name__ == "__main__":
    main()

关注@运维躬行录,在聊天框输入【u盘加密】,可免费领取打包文件及《python自动化办公教程》祝你效率翻倍

文章目录

博主介绍

热爱技术的云计算运维工程师,Python全栈工程师,分享开发经验与生活感悟。
欢迎关注我的微信公众号@运维躬行录,领取海量学习资料

微信二维码