Archived
1
1

Refactor and cleanup

This commit is contained in:
Mona Lassa
2025-05-22 02:52:38 +02:00
parent f90695dfda
commit 5ae6b4da9a
12 changed files with 215 additions and 333 deletions
@@ -6,13 +6,13 @@ namespace MetroUnlocker.LibTSForge.Crypto
{
public static class CryptoUtils
{
public static byte[] GenerateRandomKey(int len)
public static byte[] GenerateRandomKey(int length)
{
byte[] rand = new byte[len];
Random r = new Random();
r.NextBytes(rand);
byte[] randomKey = new byte[length];
Random random = new Random();
random.NextBytes(randomKey);
return rand;
return randomKey;
}
public static byte[] AESEncrypt(byte[] data, byte[] key)
@@ -47,19 +47,19 @@ namespace MetroUnlocker.LibTSForge.Crypto
byte[] aesKey = Encoding.UTF8.GetBytes("Boop Foxyz nose!");
byte[] hmacKey = CryptoUtils.GenerateRandomKey(0x10);
byte[] encAesKey = CryptoUtils.RSAEncrypt(rsaKey, aesKey);
byte[] aesKeySig = CryptoUtils.RSASign(rsaKey, encAesKey);
byte[] hmacSig = CryptoUtils.HMACSign(hmacKey, data);
byte[] encryptedAesKey = CryptoUtils.RSAEncrypt(rsaKey, aesKey);
byte[] aesKeySignature = CryptoUtils.RSASign(rsaKey, encryptedAesKey);
byte[] hmacSignature = CryptoUtils.HMACSign(hmacKey, data);
byte[] decData = new byte[] { };
decData = decData.Concat(hmacKey).Concat(hmacSig).Concat(BitConverter.GetBytes(0)).Concat(data).ToArray();
decData = decData.Concat(hmacKey).Concat(hmacSignature).Concat(BitConverter.GetBytes(0)).Concat(data).ToArray();
byte[] encData = CryptoUtils.AESEncrypt(decData, aesKey);
BinaryWriter bw = new BinaryWriter(new MemoryStream());
bw.Write(versionTable[version]);
bw.Write(Encoding.UTF8.GetBytes("UNTRUSTSTORE"));
bw.Write(aesKeySig);
bw.Write(encAesKey);
bw.Write(aesKeySignature);
bw.Write(encryptedAesKey);
bw.Write(encData);
return bw.GetBytes();