PHP 查看 Navicat 軟件里帶星號(hào)的密碼

Navicat 一直保存密碼使用,久而久之,就把服務(wù)器的密碼忘記了。通過這個(gè)PHP代碼,就可以將保存在 Navicat 里面的密碼還原出來(lái),避免了重新修改密碼的麻煩。

第一步

打開 Navicat ,導(dǎo)入連接,注意要把導(dǎo)出密碼一起勾上。

第二步

打開導(dǎo)出的 connections.ncx 文件,Password 后面的那一串字符,就是加密后的密碼

里面有好幾種,如 Password 是直連的密碼, SSH_Password是SSH連接的密碼,按需要復(fù)制出來(lái)

第三步

打開代碼運(yùn)行工具
代碼在線運(yùn)行 - 在線工具 (tool.lu)

將以下代碼復(fù)掉進(jìn)去,滾動(dòng)到最后,將 $decode = $navicatPassword->decrypt('xxxxxxxxxxxxxx'); 中的 xxx 換成剛剛復(fù)制出來(lái)的密碼,點(diǎn)擊執(zhí)行,就能看到密碼了。


> 注意版本的選擇

<?php
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 = 11)
    {
        $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);
    }
};
 
 
//需要指定版本兩種,11或12
//$navicatPassword = new NavicatPassword(11);
$navicatPassword = new NavicatPassword(12);
 
 
//$decode = $navicatPassword->decrypt('15057D7BA390');
$decode = $navicatPassword->decrypt('xxxxxxxxxxxxxx');
echo $decode."\n";
?>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、序 不知道大家有沒有這樣的經(jīng)歷?我們經(jīng)常使用navicat連接數(shù)據(jù)庫(kù),有時(shí)候時(shí)間久了之后,會(huì)忘記之前的密碼,但...
    匠工精神閱讀 1,289評(píng)論 0 0
  • 參考:https://blog.csdn.net/weixin_40903194/article/details/...
    脆果咒閱讀 5,104評(píng)論 0 1
  • 我們?nèi)粘J褂肗avicat做數(shù)據(jù)庫(kù)管理工具的不少,但很多人卻只有第一次連接的時(shí)候知道密碼,后面因?yàn)楦鞣N原因忘記了密...
    懷老師閱讀 1,958評(píng)論 0 0
  • 主要操作: 1、導(dǎo)出連接 2、執(zhí)行解密代碼 一、導(dǎo)出連接 1、點(diǎn)擊文件->導(dǎo)出連接 2、選擇需要的鏈接 3、點(diǎn)擊【...
    小猴子滴樂樂閱讀 1,665評(píng)論 0 0
  • Setp 1 導(dǎo)出connections Setp 2 解密password 進(jìn)入網(wǎng)站 https://tool....
    Avan菜菜閱讀 835評(píng)論 0 0

友情鏈接更多精彩內(nèi)容