Python 完整实现 BCrypt GUI 工具

✅ 可以用 Python 完整实现 BCrypt GUI 工具

✅ 更容易打包成 exe(PyInstaller)

❌ 但 仍然不能"解密" BCrypt(只能生成 / 校验,原理和 Java 一样)

目录

[✅ 一、技术选型(为什么 Python 很合适)](#✅ 一、技术选型(为什么 Python 很合适))

[🧩 二、Python GUI 成品代码(直接可用)](#🧩 二、Python GUI 成品代码(直接可用))

[📦 三、打包成 Windows exe(非常简单)](#📦 三、打包成 Windows exe(非常简单))

[🔐 四、与 Java BCrypt 的兼容性(你关心这个)](#🔐 四、与 Java BCrypt 的兼容性(你关心这个))

[⚠️ 五、注意事项(非常重要)](#⚠️ 五、注意事项(非常重要))

[❌ 不能做的](#❌ 不能做的)

[✅ 合法用途](#✅ 合法用途)

[🚀 六、Python 方案 vs Java 方案对比](#🚀 六、Python 方案 vs Java 方案对比)


✅ 一、技术选型(为什么 Python 很合适)

模块 选择 原因
GUI tkinter 内置、稳定、打 exe 不坑
BCrypt bcrypt 和 Java BCrypt 同算法
打包 exe pyinstaller 成熟、一步到位

Python 版 exe 反而比 Java 更省事。

🧩 二、Python GUI 成品代码(直接可用)

📄 文件名:bcrypt_gui.py

python 复制代码
import tkinter as tk
from tkinter import messagebox, scrolledtext
import bcrypt

def encode_password():
    raw = raw_entry.get()
    if not raw:
        result("请输入明文密码", "red")
        return
    hashed = bcrypt.hashpw(raw.encode(), bcrypt.gensalt())
    encoded.delete("1.0", tk.END)
    encoded.insert(tk.END, hashed.decode())
    result("加密成功 ✔", "green")

def check_password():
    raw = raw_entry.get()
    hashed = encoded.get("1.0", tk.END).strip()

    if not raw or not hashed:
        result("请输入明文和密文", "red")
        return
    try:
        ok = bcrypt.checkpw(raw.encode(), hashed.encode())
        result("密码匹配 ✔" if ok else "密码不匹配 ✘",
               "green" if ok else "red")
    except Exception:
        messagebox.showerror("错误", "无效的 BCrypt 密文")

def result(msg, color):
    status.config(text=msg, fg=color)

root = tk.Tk()
root.title("BCrypt 密码工具")
root.geometry("500x340")
root.resizable(False, False)

tk.Label(root, text="明文密码:").pack(anchor="w", padx=12, pady=(12, 0))
raw_entry = tk.Entry(root, width=58, show="*")
raw_entry.pack(padx=12)

tk.Label(root, text="BCrypt 密文:").pack(anchor="w", padx=12, pady=(12, 0))
encoded = scrolledtext.ScrolledText(root, height=6)
encoded.pack(padx=12, pady=(0, 10))

btns = tk.Frame(root)
btns.pack(pady=5)
tk.Button(btns, text="生成加密", width=14, command=encode_password).pack(side=tk.LEFT, padx=20)
tk.Button(btns, text="校验密码", width=14, command=check_password).pack(side=tk.LEFT, padx=20)

status = tk.Label(root, text="", font=("微软雅黑", 11, "bold"))
status.pack(pady=10)

root.mainloop()

📦 三、打包成 Windows exe(非常简单)

1️⃣ 安装依赖

bash 复制代码
pip install bcrypt pyinstaller

2️⃣ 生成 exe

bash 复制代码
pyinstaller --onefile --noconsole bcrypt_gui.py

生成文件:

bash 复制代码
dist/bcrypt_gui.exe

👉 双击即可运行

🔐 四、与 Java BCrypt 的兼容性(你关心这个)

✅ 完全兼容

Python bcrypt 生成的密文:

bash 复制代码
$2b$12$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Java BCryptPasswordEncoder:

bash 复制代码
encoder.matches(raw, encoded) // ✔ 完全支持

反过来也一样。

⚠️ 五、注意事项(非常重要)

❌ 不能做的

  • 不能解密 BCrypt

  • 不能"暴力破解"

✅ 合法用途

  • 管理员初始化

  • 运维校验

  • 数据迁移验证

🚀 六、Python 方案 vs Java 方案对比

项目 Python Java
GUI 开发 ⭐⭐⭐⭐ ⭐⭐⭐
打 exe ⭐⭐⭐⭐⭐ ⭐⭐⭐
运行体积 略大 较大
长期维护 ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
相关推荐
deli0071 小时前
手机拍灯为什么有一条条黑纹?PWM 240Hz 实测
前端
wangruofeng6 小时前
AI Models 1.1.0 发布,查大模型价格、对比模型和找 API 地址
前端·aigc·ai编程
wangruofeng6 小时前
给前端开发者的 100 个设计参考网站
前端·设计
Pniubi8 小时前
怎么排查慢SQL,怎么解决?
java·数据库·sql
M--Y8 小时前
LangGraph 工作流模式
开发语言·javascript·python·langchain·大模型·llm·langgraph
岁月宁静9 小时前
DeepSeek Harness 实战与架构解析:让 Agent 从“会聊”到“能交付”
人工智能·python·agent
LiaoWL1239 小时前
NumPy 入门实战(二):向量化与余弦相似度——从 ndarray 到 Embedding
python·numpy·embedding
薛之谦_9 小时前
Java 全栈知识体系:从 IDEA 高效开发到 JVM、并发与 Stream 实战
java·jvm·intellij-idea
星栈9 小时前
视频即代码,Remotion 能做什么、不能做什么
前端·音视频开发
广州华水科技9 小时前
单北斗GNSS位移监测系统的应用与技术解析
前端