✅ 可以用 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 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| 运行体积 | 略大 | 较大 |
| 长期维护 | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |