导出数据库连接 打开导出的connections.ncx文件 找到加密的password 放入java程序中解密即可
package com.asia.card.cloud.enterprise.api;
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 {
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 void main(String[] args) throws Exception {
String encrypted = "导出文件中的加密密码";
int version = 12;
String decrypted = NavicatPassword.decrypt(encrypted, version);
System.out.println("解密结果: " + decrypted);
}
public static String decrypt(String ciphertext, int version) throws Exception {
switch (version) {
case 11:
return decryptBlowfish(ciphertext);
case 12:
return decryptAES(ciphertext);
default:
throw new IllegalArgumentException("Unsupported version: " + version);
}
}
public static String encrypt(String plaintext, int version) throws Exception {
switch (version) {
case 11:
return encryptBlowfish(plaintext);
case 12:
return encryptAES(plaintext);
default:
throw new IllegalArgumentException("Unsupported version: " + version);
}
}
// ========== Version 11: Blowfish ==========
private static String decryptBlowfish(String ciphertext) throws Exception {
byte[] iv = hexToBytes(BLOW_IV);
byte[] key = sha1(BLOW_KEY);
byte[] encrypted = hexToBytes(ciphertext.toLowerCase());
Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "Blowfish"));
byte[] currentVector = iv.clone();
StringBuilder result = new StringBuilder();
int blocks = encrypted.length / 8;
int remain = encrypted.length % 8;
for (int i = 0; i < blocks; i++) {
byte[] block = Arrays.copyOfRange(encrypted, i * 8, (i + 1) * 8);
byte[] decrypted = cipher.doFinal(block);
byte[] plain = xor(decrypted, currentVector);
currentVector = xor(currentVector, block);
result.append(new String(plain, StandardCharsets.UTF_8));
}
if (remain > 0) {
currentVector = cipher.doFinal(currentVector);
byte[] remainBytes = Arrays.copyOfRange(encrypted, blocks * 8, encrypted.length);
result.append(new String(xor(remainBytes, currentVector), StandardCharsets.UTF_8));
}
return result.toString().trim();
}
private static String encryptBlowfish(String plaintext) throws Exception {
byte[] iv = hexToBytes(BLOW_IV);
byte[] key = sha1(BLOW_KEY);
byte[] inputBytes = plaintext.getBytes(StandardCharsets.UTF_8);
int padLen = 8 - (inputBytes.length % 8);
byte[] padded = Arrays.copyOf(inputBytes, inputBytes.length + padLen); // 零填充
Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "Blowfish"));
byte[] currentVector = iv.clone();
StringBuilder result = new StringBuilder();
for (int i = 0; i < padded.length; i += 8) {
byte[] block = xor(Arrays.copyOfRange(padded, i, i + 8), currentVector);
byte[] encrypted = cipher.doFinal(block);
currentVector = xor(currentVector, encrypted);
result.append(bytesToHex(encrypted));
}
return result.toString().toUpperCase();
}
// ========== Version 12: AES ==========
private static String decryptAES(String ciphertext) throws Exception {
byte[] key = AES_KEY.getBytes(StandardCharsets.UTF_8);
byte[] iv = AES_IV.getBytes(StandardCharsets.UTF_8);
byte[] encrypted = hexToBytes(ciphertext.toLowerCase());
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv));
byte[] result = cipher.doFinal(encrypted);
return new String(result, StandardCharsets.UTF_8).trim();
}
private static String encryptAES(String plaintext) throws Exception {
byte[] key = AES_KEY.getBytes(StandardCharsets.UTF_8);
byte[] iv = AES_IV.getBytes(StandardCharsets.UTF_8);
byte[] inputBytes = plaintext.getBytes(StandardCharsets.UTF_8);
int padLen = 16 - (inputBytes.length % 16);
byte[] padded = Arrays.copyOf(inputBytes, inputBytes.length + padLen); // 零填充
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv));
byte[] result = cipher.doFinal(padded);
return bytesToHex(result).toUpperCase();
}
// ========== 工具方法 ==========
private static byte[] xor(byte[] a, byte[] b) {
byte[] result = new byte[a.length];
for (int i = 0; i < a.length; i++) {
result[i] = (byte) (a[i] ^ b[i]);
}
return result;
}
private static byte[] sha1(String input) throws Exception {
return MessageDigest.getInstance("SHA-1").digest(input.getBytes(StandardCharsets.UTF_8));
}
private static byte[] hexToBytes(String hex) {
int len = hex.length();
byte[] out = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
out[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
+ Character.digit(hex.charAt(i + 1), 16));
}
return out;
}
private static String bytesToHex(byte[] bytes) {
StringBuilder hex = new StringBuilder();
for (byte b : bytes) {
hex.append(String.format("%02X", b));
}
return hex.toString();
}
}