ID除2,加上key的值,结果转十六进制字符串,如果勾选要时间,就在十六进制字符串后追加一个z和time控件中的时间值,最后通过密钥Format2044153997加密,加密结果转16进制字符串
用java还原如下:
[Java] 纯文本查看 复制代码 package org.example;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
public class jiemi {
private static String byte2hex(byte[] data) {
StringBuilder hexString = new StringBuilder();
for (byte b : data) {
String hex = Integer.toHexString(0xFF & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString().toLowerCase();
}
public static String encrypt(String input, String key) throws Exception {
if (key.length() > 16) {
key = key.substring(0, 16);
}
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.US_ASCII), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
byte[] encrypted = cipher.doFinal(input.getBytes());
return byte2hex(encrypted);
}
public static String calculatePassword(int userId, int addValue, boolean needTime, long days, long hours, long minutes, long seconds) {
long totalMilliseconds = (days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60 + seconds) * 1000;
String hexString = Integer.toHexString((userId / 2) + addValue);
if (needTime) {
hexString += "z" + totalMilliseconds;
}
try {
return encrypt(hexString, "Format2044153997");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
int userId = 2; // 用户ID
int addValue = 8; // KEY
boolean needTime = false; // 是否要时间
long days = 1, hours = 2, minutes = 30, seconds = 45; // 示例时间
String calculatedPassword = calculatePassword(userId, addValue, needTime, days, hours, minutes, seconds);
System.out.println("Calculated Password: " + calculatedPassword);
}
}
|