首页 > 数据库 >查看Navicat16已保存的数据库连接密码

查看Navicat16已保存的数据库连接密码

时间:2024-11-11 09:57:45浏览次数:1  
标签:Navicat16 String 数据库 currentVector 密码 result return byte string

1.导出数据库连接 connections.ncx 文件

2.使用Java程序进行解密

Java在线运行环境:代码在线运行 - 在线工具,进入选择Java,将以下代码复制到在线运行环境中

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Arrays;
 
public class NavicatPassword {
	public static void main(String[] args) throws Exception {
		NavicatPassword navicatPassword = new NavicatPassword();
 
		// Navicat 11及以前的版本 轨迹星辰
        // String decode = navicatPassword.decrypt("你的密码", 11);
 
		// Navicat 12及以后的版本
		String decode = navicatPassword.decrypt("你的密码", 12);
 
		System.out.println(decode);
	}
 
	private static final String AES_KEY = "libcckeylibcckey";
	private static final String AES_IV = "libcciv libcciv ";
	private static final String BLOW_KEY = "3DC5CA39";
	private static final String BLOW_IV = "d9c7c3c8870d64bd";
 
	public static String encrypt(String plaintext, int version) throws Exception {
		switch (version) {
			case 11:
				return encryptEleven(plaintext);
			case 12:
				return encryptTwelve(plaintext);
			default:
				throw new IllegalArgumentException("Unsupported version");
		}
	}
 
	public static String decrypt(String ciphertext, int version) throws Exception {
		switch (version) {
			case 11:
				return decryptEleven(ciphertext);
			case 12:
				return decryptTwelve(ciphertext);
			default:
				throw new IllegalArgumentException("Unsupported version");
		}
	}
 
	private static String encryptEleven(String plaintext) throws Exception {
		byte[] iv = hexStringToByteArray(BLOW_IV);
		byte[] key = hashToBytes(BLOW_KEY);
 
		int round = plaintext.length() / 8;
		int leftLength = plaintext.length() % 8;
		StringBuilder result = new StringBuilder();
		byte[] currentVector = iv.clone();
 
		Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
		SecretKeySpec secretKeySpec = new SecretKeySpec(key, "Blowfish");
		cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
 
		for (int i = 0; i < round; i++) {
			byte[] block = xorBytes(plaintext.substring(i * 8, (i + 1) * 8).getBytes(), currentVector);
			byte[] temp = cipher.doFinal(block);
			currentVector = xorBytes(currentVector, temp);
			result.append(bytesToHex(temp));
		}
 
		if (leftLength > 0) {
			currentVector = cipher.doFinal(currentVector);
			byte[] block = xorBytes(plaintext.substring(round * 8).getBytes(), currentVector);
			result.append(bytesToHex(block));
		}
 
		return result.toString().toUpperCase();
	}
 
	private static String encryptTwelve(String plaintext) throws Exception {
		byte[] iv = AES_IV.getBytes();
		byte[] key = AES_KEY.getBytes();
 
		Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
		SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
		IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
		cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
 
		byte[] result = cipher.doFinal(plaintext.getBytes());
		return bytesToHex(result).toUpperCase();
	}
 
	private static String decryptEleven(String ciphertext) throws Exception {
		byte[] iv = hexStringToByteArray(BLOW_IV);
		byte[] key = hashToBytes(BLOW_KEY);
		byte[] encrypted = hexStringToByteArray(ciphertext.toLowerCase());
 
		int round = encrypted.length / 8;
		int leftLength = encrypted.length % 8;
		StringBuilder result = new StringBuilder();
		byte[] currentVector = iv.clone();
 
		Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
		SecretKeySpec secretKeySpec = new SecretKeySpec(key, "Blowfish");
		cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
 
		for (int i = 0; i < round; i++) {
			byte[] block = Arrays.copyOfRange(encrypted, i * 8, (i + 1) * 8);
			byte[] temp = xorBytes(cipher.doFinal(block), currentVector);
			currentVector = xorBytes(currentVector, block);
			result.append(new String(temp));
		}
 
		if (leftLength > 0) {
			currentVector = cipher.doFinal(currentVector);
			byte[] block = Arrays.copyOfRange(encrypted, round * 8, round * 8 + leftLength);
 
			result.append(new String(xorBytes(block, currentVector), StandardCharsets.UTF_8));
		}
 
		return result.toString();
	}
 
	private static String decryptTwelve(String ciphertext) throws Exception {
		byte[] iv = AES_IV.getBytes();
		byte[] key = AES_KEY.getBytes();
		byte[] encrypted = hexStringToByteArray(ciphertext.toLowerCase());
 
		Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
		SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
		IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
		cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
 
		byte[] result = cipher.doFinal(encrypted);
		return new String(result);
	}
 
	private static byte[] xorBytes(byte[] bytes1, byte[] bytes2) {
		byte[] result = new byte[bytes1.length];
		for (int i = 0; i < bytes1.length; i++) {
			result[i] = (byte) (bytes1[i] ^ bytes2[i]);
		}
		return result;
	}
 
	private static byte[] hexStringToByteArray(String s) {
		int len = s.length();
		byte[] data = new byte[len / 2];
		for (int i = 0; i < len; i += 2) {
			data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
		}
		return data;
	}
 
	private static byte[] hashToBytes(String s) throws Exception {
		return MessageDigest.getInstance("SHA-1").digest(s.getBytes());
	}
 
	private static String bytesToHex(byte[] bytes) {
		StringBuilder result = new StringBuilder();
		for (byte b : bytes) {
			result.append(String.format("%02X", b));
		}
		return result.toString();
	}
}

  

3.解密 - 使用PHP程序进行解密

PHP在线运行环境:代码在线运行 - 在线工具,进入后选择PHP,将以下代码复制到在线运行环境中

<?php
 
// Navicat 11及以前的版本 轨迹星辰
//$navicatPassword = new NavicatPassword(11); // Navicat 12及以后的版本 $navicatPassword = new NavicatPassword(12); $decode = $navicatPassword->decrypt('你的密码'); echo $decode . "\n"; 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); } }

  

标签:Navicat16,String,数据库,currentVector,密码,result,return,byte,string
From: https://www.cnblogs.com/qq-965324258/p/18539191

相关文章

  • HarmonyOS Next中金融支付场景的安全防护设计:基于Device Certificate Kit的无密码支付
    本文旨在深入探讨华为鸿蒙HarmonyOSNext系统(截止目前API12)的技术细节,基于实际开发实践进行总结。主要作为技术分享与交流载体,难免错漏,欢迎各位同仁提出宝贵意见和问题,以便共同进步。本文为原创内容,任何形式的转载必须注明出处及原作者。在当今数字化金融时代,便捷性与安......
  • HarmonyOS Next中金融支付场景的安全防护设计:基于Device Certificate Kit的无密码支付
    本文旨在深入探讨华为鸿蒙HarmonyOSNext系统(截止目前API12)的技术细节,基于实际开发实践进行总结。主要作为技术分享与交流载体,难免错漏,欢迎各位同仁提出宝贵意见和问题,以便共同进步。本文为原创内容,任何形式的转载必须注明出处及原作者。在当今数字化金融时代,便捷性与安全性成......
  • 基于Python电影票房数据分析可视化系统 Flask框架 豆瓣电影票房 MySQL数据库 大数据毕
    博主介绍:✌全网粉丝10W+,前互联网大厂软件研发、集结硕博英豪成立工作室。专注于计算机相关专业项目实战6年之久,选择我们就是选择放心、选择安心毕业✌>......
  • python-26-Python ORM系列之pymysql实现对数据库的增删改查及新建表
    python-26-PythonORM系列之pymysql实现对数据库的增删改查及新建表一.简介在Python基础系列ORM部分我们为大家介绍了如何搭建MySQL数据和MySQL一些访问配置,同时细节的同学应该已经了解到了ORM的2个库pymysql和sqlalchemy;PyMySQL—MySQL数据库驱动,用于与MySQL数据库......
  • 现代密码-公钥密码RSA
    实验介绍:一个密钥(公钥)是公开的,另一个密钥(私钥)必须保密,且由公钥求解私钥的计算是不可行的。RSA1选取质数p和q(pq不可公开)2计算n=pq,φ(n)=(p-1)(q-1)3随机选取整数e作为公钥,要求1<e<φ(n),e和φ(n)互质如果不互质,就没有逆元,算不出私钥。4计算私钥d,怎么计算呢,使用欧几里得算法先......
  • 劫持微信聊天记录并分析还原 —— 数据库结构讲解(四)
    本工具设计的初衷是用来获取微信账号的相关信息并解析PC版微信的数据库。        程序以Python语言开发,可读取、解密、还原微信数据库并帮助用户查看聊天记录,还可以将其聊天记录导出为csv、html等格式用于AI训练,自动回复或备份等等作用。下面我们将深入探讨这个工......
  • FTP爆破密码并登陆(期中考试)
    FTP爆破密码登陆获取flag实验要求成功爆破服务端密码并提交服务端flag.txt中的flag1、拓补图2、基础配置关闭防火墙查看服务端IPinterfaceGigabitEthernet0/0/0ipaddress192.168.66.22255.255.255.0​给AR1配置IP,并且尝试ping服务端,能通interfaceGigab......
  • MySQL数据库:本地部署数据库以及安装彩虹猫【Navicat】的安装
    文章目录一.安装前准备工作1.下载并解压文件2.修复电脑缺失的文件二.本地部署MySQL1.先解压`mysql-8.0.25-winx64.zip`,并把文件放到安装需要的位置,再把`my.ini`文件放到`mysql-8.0.25-winx64`的根目录2.修改注册表的根目录信息为自己的安装装路径3.进命令符执行`盘符+:`......
  • 【计算机毕业设计选题推荐】基于springboot湖北汽车工业科技学院校园二手商品交易系统
    ✍✍计算机编程指导师⭐⭐个人介绍:自己非常喜欢研究技术问题!专业做Java、Python、小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。⛽⛽实战项目:有源码或者技术上的问题欢迎在评论区一起讨论交流!⚡⚡Java实战|SpringBoot/SSMPython实战项目|Django微信小程......
  • 数据库系统原理大作业要求-计算机实践课程题目要求
    目录背景一、内容要求学生成绩管理系统需求要求二、提交要求背景    本文记录了自考计算机科学与技术专业的时候,遇到的C++程序设计的题目。分享出来,让同学们提前了解一下实践课程的难度。为自己的实践课程提前做准备,提前预习。一、内容要求学生成绩管理系......