navicat导出所有数据库连接详情并解密密码
navicat导出所有数据库连接详情并解密密码记一次从navicat迁移到其他软件，由于数据库比较多，有些密码都在项目里面找起来比较麻烦，于是利用navicat批量导出连接的功能去导出连接和密码步骤导出连接信息文件点击文件-导出连接全选之后选择保存位置，并勾选导出密码，点击确定之后完成导出打开导出的文件如果本机有JDK1.8+环境，请直接跳到下面一步导出默认名称是connections.ncx，重命名后缀为.xml格式，然后用编辑器打开，最好是格式化一下，看着更清晰可以看见里面的一行Connection就对应你的一个连接关键字段说明：字段名称含义ConnectionName连接名称，对应navicat列表上展示的名称ConnType数据库类型，比如Mysql、OracleHost数据库主机IP地址Port数据库主机端口Database使用的数据库，通常只有Oracle这种才有，MYSQL没有这个UserName数据库登录用户名Password数据库登录密码（加密过的，解密方法见后面）SettingsSavePath数据保存路径，比如临时缓存，sql等会储存在这个位置一般情况下，拿Host Port UserName Password Database就足够了解密密码适用于本机有JDK1.8+环境的，支持批量查看出处：https://github.com/Zhuoyuan1/navicat_password_decrypt/tree/main使用方法：克隆项目并在编译器中运行或者直接下载我打包好的Jar然后在弹出的界面中选择ncx文件显示即可解密密码第二种办法适用于无java环境的出处：https://github.com/tianhe1986/FatSmallTools使用方法：访问 https://tool.lu/coderunner/ 在线运行php复制下面代码进去，并修改倒数第二行密文的值为xml中获取到的Password值<?php namespace FatSmallTools; class NavicatPassword { protected $version = 0; protected $aesKey = 'libcckeylibcckey'; protected $aesIv = 'libcciv libcciv '; protected $blowString = '3DC5CA39'; protected $blowKey = null; protected $blowIv = null; public function __construct($version = 12) { $this->version = $version; $this->blowKey = sha1('3DC5CA39', true); $this->blowIv = hex2bin('d9c7c3c8870d64bd'); } public function encrypt($string) { $result = FALSE; switch ($this->version) { case 11: $result = $this->encryptEleven($string); break; case 12: $result = $this->encryptTwelve($string); break; default: break; } return $result; } protected function encryptEleven($string) { $round = intval(floor(strlen($string) / 8)); $leftLength = strlen($string) % 8; $result = ''; $currentVector = $this->blowIv; for ($i = 0; $i < $round; $i++) { $temp = $this->encryptBlock($this->xorBytes(substr($string, 8 * $i, 8), $currentVector)); $currentVector = $this->xorBytes($currentVector, $temp); $result .= $temp; } if ($leftLength) { $currentVector = $this->encryptBlock($currentVector); $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector); } return strtoupper(bin2hex($result)); } protected function encryptBlock($block) { return openssl_encrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING); } protected function decryptBlock($block) { return openssl_decrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING); } protected function xorBytes($str1, $str2) { $result = ''; for ($i = 0; $i < strlen($str1); $i++) { $result .= chr(ord($str1[$i]) ^ ord($str2[$i])); } return $result; } protected function encryptTwelve($string) { $result = openssl_encrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv); return strtoupper(bin2hex($result)); } public function decrypt($string) { $result = FALSE; switch ($this->version) { case 11: $result = $this->decryptEleven($string); break; case 12: $result = $this->decryptTwelve($string); break; default: break; } return $result; } protected function decryptEleven($upperString) { $string = hex2bin(strtolower($upperString)); $round = intval(floor(strlen($string) / 8)); $leftLength = strlen($string) % 8; $result = ''; $currentVector = $this->blowIv; for ($i = 0; $i < $round; $i++) { $encryptedBlock = substr($string, 8 * $i, 8); $temp = $this->xorBytes($this->decryptBlock($encryptedBlock), $currentVector); $currentVector = $this->xorBytes($currentVector, $encryptedBlock); $result .= $temp; } if ($leftLength) { $currentVector = $this->encryptBlock($currentVector); $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector); } return $result; } protected function decryptTwelve($upperString) { $string = hex2bin(strtolower($upperString)); return openssl_decrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv); } } use FatSmallTools\NavicatPassword; //需要指定版本，11 或 12，12 以上用 12，以下用 11 $navicatPassword = new NavicatPassword(12); //$navicatPassword = new NavicatPassword(11); //解密 $decode = $navicatPassword->decrypt('密文'); echo $decode."\n";可以看到，正常输出了密码123456