2022-04-17 20:43:07 +08:00
|
|
|
package emu.grasscutter.utils;
|
|
|
|
|
|
|
|
import java.security.SecureRandom;
|
|
|
|
import java.util.Base64;
|
|
|
|
|
|
|
|
import emu.grasscutter.Grasscutter;
|
|
|
|
import emu.grasscutter.net.proto.GetPlayerTokenRspOuterClass.GetPlayerTokenRsp;
|
|
|
|
import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp;
|
|
|
|
|
2022-05-11 12:30:07 +08:00
|
|
|
import static emu.grasscutter.Configuration.*;
|
|
|
|
|
2022-04-18 13:11:27 +08:00
|
|
|
public final class Crypto {
|
|
|
|
private static final SecureRandom secureRandom = new SecureRandom();
|
2022-04-17 20:43:07 +08:00
|
|
|
|
|
|
|
public static byte[] DISPATCH_KEY;
|
2022-05-13 04:04:44 +08:00
|
|
|
public static byte[] DISPATCH_SEED;
|
|
|
|
|
2022-04-17 20:43:07 +08:00
|
|
|
public static byte[] ENCRYPT_KEY;
|
2022-05-13 04:04:44 +08:00
|
|
|
public static long ENCRYPT_SEED = Long.parseUnsignedLong("11468049314633205968");
|
|
|
|
public static byte[] ENCRYPT_SEED_BUFFER = new byte[0];
|
2022-04-17 20:43:07 +08:00
|
|
|
|
|
|
|
public static void loadKeys() {
|
2022-05-17 18:00:52 +08:00
|
|
|
DISPATCH_KEY = FileUtils.readResource("/keys/dispatchKey.bin");
|
|
|
|
DISPATCH_SEED = FileUtils.readResource("/keys/dispatchSeed.bin");
|
2022-05-13 04:04:44 +08:00
|
|
|
|
2022-05-17 18:00:52 +08:00
|
|
|
ENCRYPT_KEY = FileUtils.readResource("/keys/secretKey.bin");
|
|
|
|
ENCRYPT_SEED_BUFFER = FileUtils.readResource("/keys/secretKeyBuffer.bin");
|
2022-04-17 20:43:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void xor(byte[] packet, byte[] key) {
|
|
|
|
try {
|
|
|
|
for (int i = 0; i < packet.length; i++) {
|
|
|
|
packet[i] ^= key[i % key.length];
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Grasscutter.getLogger().error("Crypto error.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte[] createSessionKey(int length) {
|
|
|
|
byte[] bytes = new byte[length];
|
|
|
|
secureRandom.nextBytes(bytes);
|
2022-05-13 04:04:44 +08:00
|
|
|
return bytes;
|
2022-04-17 20:43:07 +08:00
|
|
|
}
|
|
|
|
}
|