文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

如何查看Navicat加密的数据库密码

2023-04-20 11:14

关注

查看Navicat加密的数据库密码

背景:本机装的mysql数据库密码忘记了,打开了Navicat连接过数据库,不过密码是加密的,既然能加密那就能解密,哈哈哈哈。

解密后发现密码居然是password,好尴尬

1、打开运行窗口,输入regedit,点击确认按钮,打开注册表编辑器

如何查看Navicat加密的数据库密码

2、在注册表中找到Navicat加密后的密码

如何查看Navicat加密的数据库密码

如何查看Navicat加密的数据库密码

如何查看Navicat加密的数据库密码

如何查看Navicat加密的数据库密码

3、打开PHP在线运行工具,粘贴解密代码

<?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 = 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);
    }
};

//需要指定版本两种,11或12
//$navicatPassword = new NavicatPassword(11);
$navicatPassword = new NavicatPassword(12);
 
//解密
//$decode = $navicatPassword->decrypt('15057D7BA390');
$decode = $navicatPassword->decrypt('E75BF077AB8BAA3AC2D5');  // 替换成上一步的数据数值
echo $decode."\n";
?>

4. 修改倒数第三行NavicatPassword的版本值

5、更改倒数第二行decrypt()方法中的字符串为Navicat加密后的密码

6、点击执行,右侧得到解密后的密码

如何查看Navicat加密的数据库密码

附录:navicat找出加密的密码

使用【Win】+ 【R】组合快捷键,快速打开运行命令框,在打开后面键入命令:【Regedit】打开注册表编辑器

文件路径:

计算机\HKEY_CURRENT_USER\SOFTWARE\PremiumSoft\Navicat\Servers\

以Navicat16为例,通过上方路径,找到注册表中存储密码值的位置(如下图),选中要查看密码的连接名称,双击Pwd项,复制对应的值,至此获得了密文

如何查看Navicat加密的数据库密码

Navicat导出(推荐)

以Navicat16为例,菜单栏上点击文件,选择导出连接...,一定要选中导出密码!!!导出格式为*.ncx(该ncx本质上是XML文件,文件中包含连接的全部信息)

注:Navicat11版本没有勾选导出密码选项,直接导出即可;Navicat12+版本要勾选【导出密码】选项!

如何查看Navicat加密的数据库密码

如何查看Navicat加密的数据库密码

解密密文

Go

https://www.nhooo.com/tool/Java8/

运行代码

Go

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Arrays;
public class Main {
    public static void main(String []args) {
//navicat11解密        Navicat11Cipher de = new Navicat11Cipher();
        System.out.println(de.decryptString("密文放此处"));
//navicat12+解密        Navicat12Cipher de12 = new Navicat12Cipher();
        System.out.println(de12.decryptString("密文放此处"));
    }
    static class Navicat11Cipher {
        public static final String DefaultUserKey = "3DC5CA39";
        private static byte[] _IV;
        private static SecretKeySpec _Key;
        private static Cipher _Encryptor;
        private static Cipher _Decryptor;
        private static void initKey(String UserKey) {
            try {
                MessageDigest sha1 = MessageDigest.getInstance("SHA1");
byte[] userkey_data = UserKey.getBytes(StandardCharsets.UTF_8);
                sha1.update(userkey_data, 0, userkey_data.length);
                _Key = new SecretKeySpec(sha1.digest(), "Blowfish");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        private static void initChiperEncrypt() {
            try {
// Must use NoPadding                _Encryptor = Cipher.getInstance("Blowfish/ECB/NoPadding");
                _Encryptor.init(Cipher.ENCRYPT_MODE, _Key);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        private static void initChiperDecrypt() {
            try {
// Must use NoPadding                _Decryptor = Cipher.getInstance("Blowfish/ECB/NoPadding");
                _Decryptor.init(Cipher.DECRYPT_MODE, _Key);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        private static void initIV() {
            try {
byte[] initVec = DatatypeConverter.parseHexBinary("FFFFFFFFFFFFFFFF");
                _IV = _Encryptor.doFinal(initVec);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        private void xorBytes(byte[] a, byte[] b) {
for (int i = 0; i < a.length; i++) {
int aVal = a[i] & 0xff; // convert byte to integerint bVal = b[i] & 0xff;
                a[i] = (byte) (aVal ^ bVal); // xor aVal and bVal and typecast to byte            }
        }
        private void xorBytes(byte[] a, byte[] b, int l) {
for (int i = 0; i < l; i++) {
int aVal = a[i] & 0xff; // convert byte to integerint bVal = b[i] & 0xff;
                a[i] = (byte) (aVal ^ bVal); // xor aVal and bVal and typecast to byte            }
        }
        static {
            initKey(DefaultUserKey);
            initChiperEncrypt();
            initChiperDecrypt();
            initIV();
        }
        private byte[] Encrypt(byte[] inData) {
            try {
byte[] CV = Arrays.copyOf(_IV, _IV.length);
byte[] ret = newbyte[inData.length];
int blocks_len = inData.length / 8;
int left_len = inData.length % 8;
for (int i = 0; i < blocks_len; i++) {
byte[] temp = Arrays.copyOfRange(inData, i * 8, (i * 8) + 8);
                    xorBytes(temp, CV);
                    temp = _Encryptor.doFinal(temp);
                    xorBytes(CV, temp);
                    System.arraycopy(temp, 0, ret, i * 8, 8);
                }
if (left_len != 0) {
                    CV = _Encryptor.doFinal(CV);
byte[] temp = Arrays.copyOfRange(inData, blocks_len * 8, (blocks_len * 8) + left_len);
                    xorBytes(temp, CV, left_len);
                    System.arraycopy(temp, 0, ret, blocks_len * 8, temp.length);
                }
return ret;
            } catch (Exception e) {
                e.printStackTrace();
return null;
            }
        }
        public String encryptString(String inputString) {
            try {
byte[] inData = inputString.getBytes(StandardCharsets.UTF_8);
byte[] outData = Encrypt(inData);
return DatatypeConverter.printHexBinary(outData);
            } catch (Exception e) {
                e.printStackTrace();
return"";
            }
        }
        private byte[] Decrypt(byte[] inData) {
            try {
byte[] CV = Arrays.copyOf(_IV, _IV.length);
byte[] ret = newbyte[inData.length];
int blocks_len = inData.length / 8;
int left_len = inData.length % 8;
for (int i = 0; i < blocks_len; i++) {
byte[] temp = Arrays.copyOfRange(inData, i * 8, (i * 8) + 8);
                    temp = _Decryptor.doFinal(temp);
                    xorBytes(temp, CV);
                    System.arraycopy(temp, 0, ret, i * 8, 8);
for (int j = 0; j < CV.length; j++) {
                        CV[j] = (byte) (CV[j] ^ inData[i * 8 + j]);
                    }
                }
if (left_len != 0) {
                    CV = _Encryptor.doFinal(CV);
byte[] temp = Arrays.copyOfRange(inData, blocks_len * 8, (blocks_len * 8) + left_len);
                    xorBytes(temp, CV, left_len);
for (int j = 0; j < temp.length; j++) {
                        ret[blocks_len * 8 + j] = temp[j];
                    }
                }
return ret;
            } catch (Exception e) {
                e.printStackTrace();
return null;
            }
        }
        public String decryptString(String hexString) {
            try {
byte[] inData = DatatypeConverter.parseHexBinary(hexString);
byte[] outData = Decrypt(inData);
returnnew String(outData, StandardCharsets.UTF_8);
            } catch (Exception e) {
                e.printStackTrace();
return"";
            }
        }
    }
    static class Navicat12Cipher {
        private static SecretKeySpec _AesKey;
        private static IvParameterSpec _AesIV;
        static {
            _AesKey = new SecretKeySpec("libcckeylibcckey".getBytes(StandardCharsets.UTF_8), "AES");
            _AesIV = new IvParameterSpec("libcciv libcciv ".getBytes(StandardCharsets.UTF_8));
        }
        public String encryptString(String plaintext) {
            try {
                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                cipher.init(Cipher.ENCRYPT_MODE, _AesKey, _AesIV);
byte[] ret = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8));
return DatatypeConverter.printHexBinary(ret);
            } catch (Exception e) {
                e.printStackTrace();
return"";
            }
        }
        public String decryptString(String ciphertext) {
            try {
                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                cipher.init(Cipher.DECRYPT_MODE, _AesKey, _AesIV);
byte[] ret = cipher.doFinal(DatatypeConverter.parseHexBinary(ciphertext));
returnnew String(ret, StandardCharsets.UTF_8);
            } catch (Exception e) {
                e.printStackTrace();
return"";
            }
        }
    }
}

到此这篇关于如何查看Navicat加密的数据库密码的文章就介绍到这了,更多相关Navicat查看数据库密码内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯