This commit is contained in:
qaiu
2024-10-23 18:04:34 +08:00
parent 821fc945cf
commit a3220c36c1
10 changed files with 305 additions and 152 deletions

View File

@@ -329,73 +329,4 @@ public class AESUtils {
return _0x53928f + "-" + _0x430930 + "-" + _0x49ec94;
}
public static String encrypt(String str, String pwd) {
if (pwd == null || pwd.length() <= 0) {
throw new IllegalArgumentException("Please enter a password with which to encrypt the message.");
}
// 生成 prand 值
StringBuilder prand = new StringBuilder();
for (int i = 0; i < pwd.length(); i++) {
prand.append((int) pwd.charAt(i));
}
// 计算 sPos, mult, incr, modu
int sPos = prand.length() / 5;
long mult = Long.parseLong(prand.substring(sPos, sPos + 1) +
prand.substring(sPos * 2, sPos * 2 + 1) +
prand.substring(sPos * 3, sPos * 3 + 1) +
prand.substring(sPos * 4, sPos * 4 + 1) +
prand.substring(sPos * 5, sPos * 5 + 1));
int incr = (int) Math.ceil(pwd.length() / 2.0);
long modu = (long) Math.pow(2, 31) - 1;
if (mult < 2) {
throw new IllegalArgumentException("Algorithm cannot find a suitable hash. Please choose a different password.");
}
// 生成 salt 并加到 prand 上
long salt = Math.round(Math.random() * 1000000000) % 100000000;
prand.append(salt);
// 使用 BigInteger 处理超过 Long 范围的 prand 值
BigInteger prandValue = new BigInteger(prand.toString());
while (prandValue.toString().length() > 10) {
prandValue = prandValue.divide(BigInteger.TEN).add(prandValue.remainder(BigInteger.TEN));
}
// 将 prand 转换为 long 进行后续处理
prandValue = prandValue.multiply(BigInteger.valueOf(mult)).add(BigInteger.valueOf(incr)).mod(BigInteger.valueOf(modu));
// 加密过程
StringBuilder encStr = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
// 将字符和异或的结果强制转换为 int
int encChr = (int) (str.charAt(i) ^ (int) ((prandValue.doubleValue() / modu) * 255));
String hexStr = Integer.toHexString(encChr);
if (hexStr.length() < 2) {
encStr.append("0");
}
encStr.append(hexStr);
prandValue = prandValue.multiply(BigInteger.valueOf(mult)).add(BigInteger.valueOf(incr)).mod(BigInteger.valueOf(modu));
}
// 将 salt 转换为 16 进制并追加到加密结果
String saltHex = Long.toHexString(salt);
while (saltHex.length() < 8) {
saltHex = "0" + saltHex;
}
encStr.append(saltHex);
return encStr.toString();
}
public static void main(String[] args) {
// 示例
String encrypted = encrypt("HelloWorld", "password123");
System.out.println("Encrypted String: " + encrypted);
}
}

View File

@@ -167,8 +167,10 @@ public interface JsContent {
}
var salt = Math.round(Math.random() * 1000000000) % 100000000;
prand += salt;
var flag = 1;
while (prand.length > 10) {
prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
prand = (parseInt(prand.substring(0, 10)) + (flag ?parseFloat(prand.substring(10, prand.length)) : parseInt(prand.substring(10, prand.length)) )).toString();
flag = 0;
}
prand = (mult * prand + incr) % modu;
var enc_chr = "";

View File

@@ -8,8 +8,6 @@ import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import static cn.qaiu.util.AESUtils.encrypt;
/**
* 执行Js脚本
*
@@ -85,13 +83,10 @@ public class JsExecUtils {
public static void main(String[] args) {
//encrypt("ZYcEEs2JdncXG8zAaytJiXxmbyhH2wxb", "Hm_Iuvt_cdb524f42f23cer9b268564v7y735ewrq2324")
//'7909e8e754545a61ba4bc3c90c82cb6c69b6859d5ea2e46a6bf913d1b4f11dee011dced1'
// 1e3170f1cc1ca75172409e443b89261ec777e190ebc595b458b8e114a912a9544d2b467323f8ca011b2ed0
// 93a44ef48949d950c91303c84d36
// 95dea502a45fb153f68d8da0bf8e4a095a001e396f60837e9c1b58a48969eb77038234d2
// 93c3750f6ccf9d11b5c304b32495
System.out.println(getKwSign("Hm_lvt_cdb524f42f0ce19b169a8071123a4797", "1729503755"));
System.out.println(getKwSign("HelloWorld", "password123"));
// 1a9b1a33222a78d6506e0aeaacf5b9b69984954de79e98e3ef4766c009025b7000000000
// acb0a82caa6ee641ca99ad81ace7081f58412e2148619827aa0a038a8d76c75000000000
// f7a05b893131238ee4d1f31a85401b64056bb09988b5b9c2b87c12542578360600000000
System.out.println(getKwSign("c7nkKBeXXzCyTQ8Wc8DRNYc4Th3f6hTE", "Hm_Iuvt_cdb524f42f23cer9b268564v7y735ewrq2324"));
}