查看navicat加密的数据库密码
背景:本机装的mysql数据库密码忘记了,打开了navicat连接过数据库,不过密码是加密的,既然能加密那就能解密,哈哈哈哈。
解密后发现密码居然是password,好尴尬
1、打开运行窗口,输入regedit,点击确认按钮,打开注册表编辑器

2、在注册表中找到navicat加密后的密码
- 展开【hkey_current_user】
- 展开【software】
- 展开【premiumsoft】
- 展开【navicatpg】
- 展开【servers】
- 选择 【mysql】
- 右侧找到 pwd,双击并复制数值数据




3、打开php在线运行工具,粘贴解密代码
- 工具地址:https://tool.lu/coderunner
- 复制解密代码到工具中
<?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(11.2.7、12.1.15、15.1.17、16.0.6上述版本均已通过测试)
- 进入注册表进行查询
使用【win】+ 【r】组合快捷键,快速打开运行命令框,在打开后面键入命令:【regedit】打开注册表编辑器
文件路径:
计算机\hkey_current_user\software\premiumsoft\navicat\servers\
以navicat16为例,通过上方路径,找到注册表中存储密码值的位置(如下图),选中要查看密码的连接名称,双击pwd项,复制对应的值,至此获得了密文

navicat导出(推荐)
以navicat16为例,菜单栏上点击文件,选择导出连接...,一定要选中导出密码!!!导出格式为*.ncx(该ncx本质上是xml文件,文件中包含连接的全部信息)
注:navicat11版本没有勾选导出密码选项,直接导出即可;navicat12+版本要勾选【导出密码】选项!


解密密文
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查看数据库密码内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论