最近公司收到Navicat律师告知书,让停止使用Navicat,用了那么久的数据库连接工具,不得不换其他的。
最终选择了开源的DBeaver。
安装完DBeaver后,把Navicat导出的connections.ncx文件直接导入DBeaver。直接访问提示连接失败,因为connections.ncx文件里的密码都是加密的。
如图:
网上找了许久方法,有PHP的,复制代码去线上执行,反正跑不动,有python的,但也搞不定。
后来自己写了一个,大家可以直接使用:
#!/usr/bin/env python3 import sys from Crypto.Hash import SHA1 from Crypto.Cipher import AES, Blowfish from Crypto.Util import strxor, Padding import xml.etree.ElementTree as ETclass Navicat11Crypto:def __init__(self, Key = b'3DC5CA39'):self._Key = SHA1.new(Key).digest()self._Cipher = Blowfish.new(self._Key, Blowfish.MODE_ECB)self._IV = self._Cipher.encrypt(b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF')def decrypt_string(self, s: str):if type(s) != str:raise TypeError('Parameter s must be str.')else:plaintext = b''ciphertext = bytes.fromhex(s)cv = self._IVfull_round, left_length = divmod(len(ciphertext), 8)for i in range(0, full_round * 8, 8):t = self._Cipher.decrypt(ciphertext[i:i + 8])t = strxor.strxor(t, cv)plaintext += tcv = strxor.strxor(cv, ciphertext[i:i + 8])if left_length != 0:cv = self._Cipher.encrypt(cv)plaintext += strxor.strxor(ciphertext[8 * full_round:], cv[:left_length])return plaintext.decode('ascii')if __name__ == '__main__':pc = Navicat11Crypto()xml_path_x = r'C:\Users\xxxx\connections-all-20241219.ncx'xml_path_y = r"C:\Users\xxxxx\connections.ncx"tree = ET.parse(xml_path_y)root_element = tree.getroot()for child in root_element:print('---------------------------------')print('ConnectionName:', child.attrib['ConnectionName'])print('Host:', child.attrib['Host'])print('Port:', child.attrib['Port'])print('UserName:', child.attrib['UserName'])Password1 = pc.decrypt_string(child.attrib['Password'])print('Password:', Password1)print('SSH_Host:', child.attrib['SSH_Host'])print('SSH_Port:', child.attrib['SSH_Port'])print('SSH_UserName:', child.attrib['SSH_UserName'])Password2 = pc.decrypt_string(child.attrib['SSH_Password'])print('SSH_Password:', Password2)print('------------------------------------')
执行结果: