文章

在 Navicat 中查看连接密码

在 Navicat 中查看连接密码

Navicat 是一款流行的数据库管理工具,但如果你在连接后忘记了密码,仍然可以通过一些步骤找到它。

步骤 1:导出连接信息

  1. 打开 Navicat:启动 Navicat 应用程序。
  2. 选择文件选项:在菜单栏中,点击“文件”选项。
  3. 导出连接:选择“导出连接”选项。
  4. 选择数据库:在弹出的窗口中,勾选需要导出的数据库连接。
  5. 勾选导出密码:确保勾选“导出密码”选项,以便在导出的文件中包含密码信息。
  6. 保存文件:选择保存位置,导出后将生成一个名为 connections.ncx 的文件。

image-20250109224838274

步骤 2:解密密码

导出的 connections.ncx 文件中包含加密的密码。我们可以使用 Python 脚本来解密它。以下是解密密码的示例代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-

from Crypto.Cipher import AES
from binascii import b2a_hex, a2b_hex


# 如果text不足16位的倍数就用空格补足为16位
def add_to_16(text):
    if len(text.encode('utf-8')) % 16:
        add = 16 - (len(text.encode('utf-8')) % 16)
    else:
        add = 0
    text = text + ('\0' * add)
    return text.encode('utf-8')


# 加密函数
def encrypt(text):
    key = 'libcckeylibcckey'.encode('utf-8')
    mode = AES.MODE_CBC
    iv = b'libcciv libcciv '
    text = add_to_16(text)
    cryptos = AES.new(key, mode, iv)
    cipher_text = cryptos.encrypt(text)
    print(b2a_hex(cipher_text))
    # 因为AES加密后的字符串不一定是ascii字符集的,输出保存可能存在问题,所以这里转为16进制字符串
    return b2a_hex(cipher_text)


# 解密后,去掉补足的空格用strip() 去掉
def decrypt(text):
    key = 'libcckeylibcckey'.encode('utf-8')
    iv = b'libcciv libcciv '
    mode = AES.MODE_CBC
    cryptos = AES.new(key, mode, iv)
    plain_text = cryptos.decrypt(a2b_hex(text))
    return bytes.decode(plain_text).rstrip('\0').replace('','')



if __name__ == '__main__':
    # e=encrypt('root')
    d = decrypt('密码')  # 解密
    # print("加密:",e)
    print("解密:", d)

代码说明

  • add_to_16:这个函数用于将文本填充到16的倍数,以适应 AES 加密的要求。
  • decrypt:这个函数接受加密的密码并返回解密后的密码。
  • main:在主程序中,替换 encrypted_password 为你在 connections.ncx 文件中找到的加密密码,然后运行脚本即可得到解密后的密码。
本文由作者按照 CC BY 4.0 进行授权