83 lines
3.0 KiB
Python
83 lines
3.0 KiB
Python
import tkinter as tk
|
|
from tkinter import messagebox
|
|
from Crypto.Cipher import AES, Blowfish
|
|
import binascii
|
|
|
|
class NavicatPassword:
|
|
def __init__(self, version=12):
|
|
self.version = version
|
|
self.aes_key = b'libcckeylibcckey'
|
|
self.aes_iv = b'libcciv libcciv '
|
|
self.blow_key = b'\x3D\xC5\xCA\x39'
|
|
self.blow_iv = b'\xD9\xC7\xC3\xC8\x87\x0D\x64\xBD'
|
|
|
|
def decrypt(self, encrypted_str):
|
|
if self.version == 11:
|
|
return self.decrypt_eleven(encrypted_str)
|
|
elif self.version == 12:
|
|
return self.decrypt_twelve(encrypted_str)
|
|
return None
|
|
|
|
def decrypt_eleven(self, encrypted_str):
|
|
data = binascii.unhexlify(encrypted_str.lower())
|
|
result = b''
|
|
iv = self.blow_iv
|
|
|
|
for i in range(0, len(data), 8):
|
|
block = data[i:i+8]
|
|
decrypted = self.blowfish_decrypt(block)
|
|
result += self.xor_bytes(decrypted, iv)
|
|
iv = self.xor_bytes(iv, block)
|
|
|
|
return result.decode('utf-8')
|
|
|
|
def decrypt_twelve(self, encrypted_str):
|
|
data = binascii.unhexlify(encrypted_str.lower())
|
|
cipher = AES.new(self.aes_key, AES.MODE_CBC, self.aes_iv)
|
|
return cipher.decrypt(data).decode('utf-8').rstrip('\x00')
|
|
|
|
def blowfish_decrypt(self, data):
|
|
cipher = Blowfish.new(self.blow_key, Blowfish.MODE_ECB)
|
|
return cipher.decrypt(data)
|
|
|
|
def xor_bytes(self, a, b):
|
|
return bytes([x ^ y for x, y in zip(a, b)])
|
|
|
|
class App:
|
|
def __init__(self, root):
|
|
self.root = root
|
|
self.root.title("Navicat密码解密工具")
|
|
|
|
self.version = tk.IntVar(value=12)
|
|
self.password = tk.StringVar()
|
|
|
|
self.create_widgets()
|
|
|
|
def create_widgets(self):
|
|
tk.Label(self.root, text="Navicat版本:").grid(row=0, column=0, padx=5, pady=5)
|
|
tk.Radiobutton(self.root, text="11", variable=self.version, value=11).grid(row=0, column=1, sticky="w")
|
|
tk.Radiobutton(self.root, text="12", variable=self.version, value=12).grid(row=0, column=2, sticky="w")
|
|
|
|
tk.Label(self.root, text="加密密码:").grid(row=1, column=0, padx=5, pady=5)
|
|
tk.Entry(self.root, textvariable=self.password, width=30).grid(row=1, column=1, columnspan=2)
|
|
|
|
tk.Button(self.root, text="解密", command=self.decrypt_password).grid(row=2, column=1, pady=10)
|
|
|
|
def decrypt_password(self):
|
|
password = self.password.get().strip()
|
|
if not password:
|
|
messagebox.showerror("错误", "请输入加密密码")
|
|
return
|
|
|
|
try:
|
|
navicat = NavicatPassword(self.version.get())
|
|
result = navicat.decrypt(password)
|
|
messagebox.showinfo("解密结果", f"解密后的密码是:\n{result}")
|
|
except Exception as e:
|
|
messagebox.showerror("错误", f"解密失败:{str(e)}")
|
|
|
|
if __name__ == "__main__":
|
|
root = tk.Tk()
|
|
app = App(root)
|
|
root.mainloop()
|