1、导出连接:connections.ncx文件
此处选择要导出的连接并勾选导出密码!!!
2、找到加密密码进行破解
在connections.ncx文件中找到Password
3、通过程序进行破解
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 {
NavicatPassword navicatPassword = new NavicatPassword();
String decode = navicatPassword.decrypt("加密后的密码", 12);
System.out.println(decode);
}
public 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 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 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 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 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 byte[] hashToBytes(String s) throws Exception {
return MessageDigest.getInstance("SHA-1").digest(s.getBytes());
}
}