文章目录
前言
日常工作中我们使用FinalShell连接我们的服务器,时间久了难免会忘记之前的密码,这个时候想要查看之前保存的密码,发现已经加密了,今天给大家推荐两种方法查看已经保存的连接密码。
方法一:在线一键解密(推荐)
首先登陆到在线解密的工具网址 链接
工具页面下方有使用教程,根据教程即可完成在线解密。
方法二: 自己运行java代码解密。
1. 打开FinaShell客户端.
点击左上角文件夹图表,在展开的连接菜单中找到你要找回密码的连接信息
右键后找到最下面的导出,然后选择“选中”
2. 打开导出的连接信息json文件
找出"password"字段,并且复制后面的加密内容如图中所示。“ciNoT3B0RDuqp2fGa+9wO6dc6WjeoKVCu0r5KJmdHeM=”
3. 把上一步获取的加密字符串替换后运行下面的代码即可输出解密的密码。
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;
import java.util.Random;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
public class FinalShellDecodePass {
public static void main(String[] args) throws Exception {
System.out.print(decodePassword("这里输入你的加密字符串"));
}
public static byte[] decryptDes(byte[] data, byte[] key) throws Exception {
SecureRandom secureRandom = new SecureRandom();
DESKeySpec desKeySpec = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, secretKey, secureRandom);
return cipher.doFinal(data);
}
public static String decodePassword(String data) throws Exception {
if (data == null) {
return null;
} else {
byte[] decodedData = Base64.getDecoder().decode(data);
byte[] head = new byte[8];
System.arraycopy(decodedData, 0, head, 0, head.length);
byte[] encryptedData = new byte[decodedData.length - head.length];
System.arraycopy(decodedData, head.length, encryptedData, 0, encryptedData.length);
byte[] decryptedData = decryptDes(encryptedData, generateRandomKey(head));
return new String(decryptedData);
}
}
static byte[] generateRandomKey(byte[] head) {
long seed = 3680984568597093857L / (long) (new Random((long) head[5])).nextInt(127);
Random random = new Random(seed);
int t = head[0];
for (int i = 0; i < t; ++i) {
random.nextLong();
}
long n = random.nextLong();
Random random2 = new Random(n);
long[] keyData = {(long) head[4], random2.nextLong(), (long) head[7], (long) head[3], random2.nextLong(),
(long) head[1], random.nextLong(), (long) head[2]};
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
for (long l : keyData) {
try {
dos.writeLong(l);
} catch (IOException e) {
e.printStackTrace();
}
}
try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
byte[] key = bos.toByteArray();
return md5Hash(key);
}
public static byte[] md5Hash(byte[] data) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(data, 0, data.length);
byte[] result = messageDigest.digest();
return result;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
}