Repository navigation
希望添加一个hexhub的导入功能 #7
Copy link
Copy link
Open
Description
hexhub的官网是 https://www.hexhub.cn,这个也是一个可以连接多种ssh/数据库的软件,
这个导出数据的时候,若是没有设置密码,导出的是json,导出的数据中密码的解密方案为
import base64
import tkinter as tk
from tkinter import messagebox
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives.padding import PKCS7
KEY = b"CsN#&Uc!aOUQbh&B"
IV = b"w6KQ^MPlEx*mfHcb"
def encrypt_hexhub(text: str) -> str:
padder = PKCS7(128).padder()
padded = padder.update(text.encode("utf-8")) + padder.finalize()
cipher = Cipher(algorithms.AES(KEY), modes.CBC(IV))
encryptor = cipher.encryptor()
encrypted = encryptor.update(padded) + encryptor.finalize()
return base64.b64encode(encrypted).decode("utf-8")
def decrypt_hexhub(text: str) -> str:
encrypted = base64.b64decode(text.strip())
cipher = Cipher(algorithms.AES(KEY), modes.CBC(IV))
decryptor = cipher.decryptor()
padded = decryptor.update(encrypted) + decryptor.finalize()
unpadder = PKCS7(128).unpadder()
decrypted = unpadder.update(padded) + unpadder.finalize()
return decrypted.decode("utf-8")
class HexHubCryptoApp(tk.Tk):
def __init__(self) -> None:
super().__init__()
self.title("HexHub 加密/解密工具")
self.geometry("620x360")
self.minsize(520, 320)
self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.rowconfigure(4, weight=1)
tk.Label(self, text="输入字符串").grid(
row=0, column=0, sticky="w", padx=16, pady=(16, 6)
)
self.input_text = tk.Text(self, height=5, wrap="word")
self.input_text.grid(row=1, column=0, sticky="nsew", padx=16)
button_frame = tk.Frame(self)
button_frame.grid(row=2, column=0, pady=12)
tk.Button(button_frame, text="加密", width=12, command=self.encrypt).pack(
side="left", padx=8
)
tk.Button(button_frame, text="解密", width=12, command=self.decrypt).pack(
side="left", padx=8
)
tk.Button(button_frame, text="复制结果", width=12, command=self.copy_result).pack(
side="left", padx=8
)
tk.Label(self, text="处理结果").grid(row=3, column=0, sticky="w", padx=16)
self.result_text = tk.Text(self, height=5, wrap="word")
self.result_text.grid(row=4, column=0, sticky="nsew", padx=16, pady=(6, 16))
def get_input(self) -> str:
return self.input_text.get("1.0", "end-1c")
def set_result(self, value: str) -> None:
self.result_text.delete("1.0", "end")
self.result_text.insert("1.0", value)
def encrypt(self) -> None:
try:
self.set_result(encrypt_hexhub(self.get_input()))
except Exception as exc:
messagebox.showerror("加密失败", str(exc))
def decrypt(self) -> None:
try:
self.set_result(decrypt_hexhub(self.get_input()))
except Exception as exc:
messagebox.showerror("解密失败", f"请输入 HexHub 导出的 Base64 密文。\n\n{exc}")
def copy_result(self) -> None:
value = self.result_text.get("1.0", "end-1c")
self.clipboard_clear()
self.clipboard_append(value)
self.update()
if __name__ == "__main__":
HexHubCryptoApp().mainloop()
Metadata
Metadata
Assignees
Labels
No labels
Activity
feigeCode commentedon Oct 22, 2026
下载扩展试试,目前开发了一个hexhub的扩展