OP 12 May, 2023 - 09:06 AM
(This post was last modified: 12 May, 2023 - 06:28 PM by levitmic. Edited 4 times in total.)
Reply
Greetings,
I need help with making Keygen for Key Decrypt.
Thanks in advance.
Updating,
When I'm using original Keygen without manual MODULUS, decoding works correct
What I need to change if I must work only with this modulus.
I need help with making Keygen for Key Decrypt.
Show ContentKey Decrypt source code:
Code:
byte[] publicExponent = new byte[129]
{
1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0
};
byte[] modulus = new byte[129]
{
27, 35, 197, 255, 171, 207, 183, 123, 78, 139,
110, 99, 223, 79, 135, 68, 170, 99, 116, 4,
124, 55, 42, 36, 179, 197, 17, 100, 239, 110,
109, 156, 23, 89, 146, 103, 154, 66, 114, 105,
176, 24, 180, 150, 219, 175, 121, 188, 233, 150,
131, 234, 131, 74, 137, 159, 143, 57, 89, 247,
49, 89, 45, 50, 198, 72, 138, 10, 11, 126,
14, 110, 211, 213, 137, 117, 59, 200, 21, 136,
176, 27, 190, 98, 137, 192, 66, 37, 197, 185,
111, 30, 103, 79, 125, 94, 201, 152, 249, 71,
44, 208, 80, 51, 179, 220, 171, 221, 229, 103,
230, 101, 235, 45, 50, 172, 216, 97, 98, 66,
11, 70, 84, 239, 73, 214, 151, 167, 0
};
public SerialKeyInformation(string key, byte[] publicExponent, byte[] modulus)
{
key = Regex.Replace(key, "[^a-zA-Z0-9\\+\\/\\=]", "");
byte[] array;
array = Convert.FromBase64String(key);
if (array.Length <= 0)
{
return;
}
int num = 0;
int num2 = array.Length;
List<byte> list = new List<byte>();
int num3 = SHA1.Create().HashSize / 8;
while (num2 > 0)
{
byte[] array2 = new byte[129];
Array.Copy(array, num, array2, 0, array2.Length);
num2 -= array2.Length;
num += array2.Length;
byte[] array3 = BigInt.PowMod(array2, publicExponent, modulus);
byte[] array4 = SHA1.Create().ComputeHash(array3, num3, array3.Length - num3);
for (int i = 0; i < array4.Length; i++)
{
if (array4[i] != array3[i])
{
return;
}
}
byte[] array5 = new byte[129 - (4 + num3 + 1 + 1)];
Array.Copy(array3, 4 + num3, array5, 0, array3.Length - 1 - (4 + num3 + 1));
list.AddRange(array5);
}
byte[] array6 = list.ToArray();
uint num4 = 0u;
bool flag = false;
while (!flag && num4 < array6.Length)
{
LicenseFieldType licenseFieldType;
licenseFieldType = (LicenseFieldType)array6[num4];
num4++;
switch (licenseFieldType)
{
case LicenseFieldType.RegistrationName:
case LicenseFieldType.RegistrationEMail:
{
num4 += 4;
byte[] array10 = new byte[4];
Array.Copy(array6, num4, array10, 0L, array10.Length);
num4 += (uint)array10.Length;
uint num9 = (uint)(array10[0] | (array10[1] << 8) | (array10[2] << 16) | (array10[3] << 24));
string @string;
@string = Encoding.UTF8.GetString(array6, (int)num4, (int)num9);
num4 += num9;
switch (licenseFieldType)
{
case LicenseFieldType.RegistrationName:
this._registrationName = @string;
break;
case LicenseFieldType.RegistrationEMail:
this._registrationEMail = @string;
break;
}
break;
}
case LicenseFieldType.ExpirationDate:
case LicenseFieldType.MaximumBuildDate:
{
num4 += 4;
byte[] array9 = new byte[8];
Array.Copy(array6, num4, array9, 0L, array9.Length);
num4 += (uint)array9.Length;
ulong num8 = array9[0] | ((ulong)array9[1] << 8) | ((ulong)array9[2] << 16) | ((ulong)array9[3] << 24) | ((ulong)array9[4] << 32) | ((ulong)array9[5] << 40) | ((ulong)array9[6] << 48) | ((ulong)array9[7] << 56);
DateTime value = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(num8);
switch (licenseFieldType)
{
case LicenseFieldType.ExpirationDate:
this._expirationDate = value;
break;
case LicenseFieldType.MaximumBuildDate:
this._maximumBuildDate = value;
break;
}
break;
}
case LicenseFieldType.UserData:
{
byte[] array7 = new byte[4];
Array.Copy(array6, num4, array7, 0L, array7.Length);
num4 += (uint)array7.Length;
uint num7 = (uint)(array7[0] | (array7[1] << 8) | (array7[2] << 16) | (array7[3] << 24));
byte[] array8 = new byte[num7];
Array.Copy(array6, num4, array8, 0L, (int)num7);
num4 += num7;
this._userData = array8;
break;
}
case LicenseFieldType.NoMoreData:
flag = true;
break;
default:
{
int num5 = array6[num4++] | (array6[num4++] << 8) | (array6[num4++] << 16);
uint num6 = num4;
num4 = num6 + 1 + (uint)(num5 | (array6[num6] << 24));
break;
}
}
}
this._state = SerialKeyState.Valid;
}
Code:
public static class BigInt
{
public static byte[] PowMod(byte[] a, byte[] exp_, byte[] m)
{
byte[] array;
array = new byte[exp_.Length];
byte[] array2;
array2 = new byte[exp_.Length];
Array.Copy(exp_, array2, exp_.Length);
byte[] array3;
array3 = new byte[a.Length];
BigInt.Mod(a, m);
array[0] = 1;
while (!BigInt.IsZero(array2))
{
if (((uint)array2[0] & (true ? 1u : 0u)) != 0)
{
BigInt.MulMod(array, a, m);
}
Array.Copy(a, array3, a.Length);
BigInt.MulMod(a, array3, m);
BigInt.InplaceShiftRight(array2);
}
return array;
}
private static void Mod(byte[] a, byte[] m)
{
int num;
num = a.Length - 1;
while (num >= 0 && a[num] == 0)
{
num--;
}
int num2;
num2 = m.Length - 1;
while (num2 >= 0 && m[num2] == 0)
{
num2--;
}
if (num < num2)
{
return;
}
for (int i = num2; i <= num; i++)
{
while (BigInt.HighPartGreaterThan(a, num, m, num2, i))
{
BigInt.HighPartSub(a, num, m, num2, i);
}
}
}
private static bool HighPartGreaterThan(byte[] a, int a_firstNotZeroPos, byte[] b, int b_firstNotZeroPos, int partLength)
{
int num;
num = a_firstNotZeroPos;
int num2;
num2 = partLength;
while (num >= a_firstNotZeroPos - partLength)
{
if (a[num] > b[num2])
{
return true;
}
if (a[num] < b[num2])
{
return false;
}
num--;
num2--;
}
return false;
}
private static bool HighPartSub(byte[] a, int a_firstNotZeroPos, byte[] b, int b_firstNotZeroPos, int partLength)
{
int num;
num = a_firstNotZeroPos - partLength;
int num2;
num2 = 0;
bool flag;
flag = false;
while (num <= a_firstNotZeroPos)
{
if (flag)
{
if (a[num] == 0)
{
a[num] = byte.MaxValue;
flag = true;
}
else
{
a[num]--;
flag = false;
}
}
else
{
flag = false;
}
if (a[num] >= b[num2])
{
a[num] -= b[num2];
}
else
{
a[num] = (byte)(a[num] + 256 - b[num2]);
flag = true;
}
num++;
num2++;
}
return false;
}
private static bool IsZero(byte[] n)
{
for (int i = 0; i < n.Length; i++)
{
if (n[i] != 0)
{
return false;
}
}
return true;
}
public static void MulMod(byte[] a_, byte[] b_, byte[] m)
{
byte[] array;
array = new byte[a_.Length];
byte[] array2;
array2 = new byte[a_.Length];
Array.Copy(a_, array2, a_.Length);
byte[] array3;
array3 = new byte[b_.Length];
Array.Copy(b_, array3, b_.Length);
while (!BigInt.IsZero(array2))
{
if (((uint)array2[0] & (true ? 1u : 0u)) != 0)
{
BigInt.Add(array, array3);
BigInt.Mod(array, m);
}
BigInt.InplaceShiftRight(array2);
BigInt.InplaceShiftLeft(array3);
BigInt.Mod(array3, m);
}
Array.Copy(array, a_, a_.Length);
}
private static void InplaceShiftRight(byte[] a)
{
for (int i = 0; i < a.Length; i++)
{
byte b;
b = (byte)((i < a.Length - 1) ? ((byte)(a[i + 1] & 1u)) : 0);
a[i] >>= 1;
a[i] |= (byte)(b << 7);
}
}
private static void Add(byte[] a, byte[] b)
{
byte b2;
b2 = 0;
int i;
for (i = 0; i < a.Length && i < b.Length; i++)
{
uint num;
num = (uint)(a[i] + b[i] + b2);
a[i] = (byte)(num & 0xFFu);
b2 = (byte)(num >> 8);
}
if (b2 != 0 && i + 1 < a.Length)
{
a[i + 1] = b2;
}
}
private static void InplaceShiftLeft(byte[] a)
{
for (int num = a.Length - 1; num >= 0; num--)
{
byte b;
b = (byte)((num > 0) ? ((byte)((a[num - 1] & -128) >> 7)) : 0);
a[num] <<= 1;
a[num] |= b;
}
}
private static void ShiftLeft(byte[] a, byte[] res)
{
for (int num = res.Length - 1; num >= 0; num--)
{
byte b;
b = (byte)((num > 0) ? ((byte)((a[num - 1] & -128) >> 7)) : 0);
res[num] <<= 1;
res[num] |= b;
}
}
}
Thanks in advance.
Updating,
When I'm using original Keygen without manual MODULUS, decoding works correct
What I need to change if I must work only with this modulus.
Show Contentmodulus:
Code:
byte[] modulus = new byte[129]
{
27, 35, 197, 255, 171, 207, 183, 123, 78, 139,
110, 99, 223, 79, 135, 68, 170, 99, 116, 4,
124, 55, 42, 36, 179, 197, 17, 100, 239, 110,
109, 156, 23, 89, 146, 103, 154, 66, 114, 105,
176, 24, 180, 150, 219, 175, 121, 188, 233, 150,
131, 234, 131, 74, 137, 159, 143, 57, 89, 247,
49, 89, 45, 50, 198, 72, 138, 10, 11, 126,
14, 110, 211, 213, 137, 117, 59, 200, 21, 136,
176, 27, 190, 98, 137, 192, 66, 37, 197, 185,
111, 30, 103, 79, 125, 94, 201, 152, 249, 71,
44, 208, 80, 51, 179, 220, 171, 221, 229, 103,
230, 101, 235, 45, 50, 172, 216, 97, 98, 66,
11, 70, 84, 239, 73, 214, 151, 167, 0
};
Show ContentOriginal Keygen:
Code:
public class KeyGen
{
private byte[] _modulus;
private byte[] _publicExponent;
private byte[] _privateExponent;
public string PublicExponent => Convert.ToBase64String(this._publicExponent);
public string PrivateExponent => Convert.ToBase64String(this._privateExponent);
public string Modulus => Convert.ToBase64String(this._modulus);
public KeyGen()
{
RSAParameters rSAParameters = new RSACryptoServiceProvider(1024).ExportParameters(includePrivateParameters: true);
this._modulus = new byte[129];
Array.Clear(this._modulus, 0, this._modulus.Length);
Array.Copy(rSAParameters.Modulus.Reverse().ToArray(), 0, this._modulus, 0, rSAParameters.Modulus.Length);
this._publicExponent = new byte[129];
Array.Clear(this._publicExponent, 0, this._publicExponent.Length);
Array.Copy(rSAParameters.Exponent.Reverse().ToArray(), 0, this._publicExponent, 0, rSAParameters.Exponent.Length);
this._privateExponent = new byte[129];
Array.Clear(this._privateExponent, 0, this._privateExponent.Length);
Array.Copy(rSAParameters.D.Reverse().ToArray(), 0, this._privateExponent, 0, rSAParameters.D.Length);
}
public KeyGen(string modulus, string publicExponent, string privateExponent)
{
this._modulus = KeyGen.Base64StringToByteArray(modulus);
this._privateExponent = KeyGen.Base64StringToByteArray(privateExponent);
this._publicExponent = KeyGen.Base64StringToByteArray(publicExponent);
}
private static byte[] Base64StringToByteArray(string str)
{
List<byte> list = new List<byte>();
list.AddRange(Convert.FromBase64String(str));
list.AddRange(new byte[129 - list.Count]);
return list.ToArray();
}
private byte[] FromStringToBytes(string str)
{
byte[] bytes = Encoding.UTF8.GetBytes(str);
byte[] array = new byte[4 + bytes.Length];
Array.Copy(this.FromUInt32ToBytes((uint)bytes.Length), array, 4);
Array.Copy(bytes, 0, array, 4, bytes.Length);
return array;
}
private byte[] FromUInt32ToBytes(uint i)
{
return new byte[4]
{
(byte)(i & 0xFFu),
(byte)((i >> 8) & 0xFFu),
(byte)((i >> 16) & 0xFFu),
(byte)(i >> 24)
};
}
private byte[] FromUInt64ToBytes(ulong i)
{
return new byte[8]
{
(byte)(i & 0xFF),
(byte)((i >> 8) & 0xFF),
(byte)((i >> 16) & 0xFF),
(byte)((i >> 24) & 0xFF),
(byte)((i >> 32) & 0xFF),
(byte)((i >> 40) & 0xFF),
(byte)((i >> 48) & 0xFF),
(byte)((i >> 56) & 0xFF)
};
}
private void AddToMessageAsByteList(List<byte> messageAsByteList, LicenseFieldType licenseFieldType, byte[] bytes)
{
messageAsByteList.Add((byte)licenseFieldType);
messageAsByteList.AddRange(this.FromUInt32ToBytes((uint)bytes.Length));
messageAsByteList.AddRange(bytes);
}
private void AddToMessageAsByteList(List<byte> messageAsByteList, LicenseFieldType licenseFieldType, string str)
{
this.AddToMessageAsByteList(messageAsByteList, licenseFieldType, this.FromStringToBytes(str));
}
private void AddToMessageAsByteList(List<byte> messageAsByteList, LicenseFieldType licenseFieldType, uint value)
{
this.AddToMessageAsByteList(messageAsByteList, licenseFieldType, this.FromUInt32ToBytes(value));
}
private void AddToMessageAsByteList(List<byte> messageAsByteList, LicenseFieldType licenseFieldType, ulong value)
{
this.AddToMessageAsByteList(messageAsByteList, licenseFieldType, this.FromUInt64ToBytes(value));
}
private void AddToMessageAsByteList(List<byte> messageAsByteList, LicenseFieldType licenseFieldType, bool value)
{
this.AddToMessageAsByteList(messageAsByteList, licenseFieldType, value ? 1u : 0u);
}
public string GenerateKey(SerialKeyInformation licenseInformation)
{
List<byte> list = new List<byte>();
if (licenseInformation.RegistrationName != null)
{
this.AddToMessageAsByteList(list, LicenseFieldType.RegistrationName, licenseInformation.RegistrationName);
}
if (licenseInformation.RegistrationEMail != null)
{
this.AddToMessageAsByteList(list, LicenseFieldType.RegistrationEMail, licenseInformation.RegistrationEMail);
}
if (licenseInformation.ExpirationDate.HasValue)
{
this.AddToMessageAsByteList(list, LicenseFieldType.ExpirationDate, (ulong)licenseInformation.ExpirationDate.Value.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
}
if (licenseInformation.MaximumBuildDate.HasValue)
{
this.AddToMessageAsByteList(list, LicenseFieldType.MaximumBuildDate, (ulong)licenseInformation.MaximumBuildDate.Value.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
}
if (licenseInformation.UserData != null)
{
this.AddToMessageAsByteList(list, LicenseFieldType.UserData, licenseInformation.UserData);
}
list.Add(byte.MaxValue);
byte[] array = list.ToArray();
int num = 0;
int num2 = array.Length;
int num3 = SHA1.Create().HashSize / 8;
List<byte> list2 = new List<byte>();
while (num2 > 0)
{
byte[] array2 = new byte[129];
int num4 = 0 + num3;
int num5 = num4;
byte[] array3 = new byte[4];
new Random().NextBytes(array3);
Array.Copy(array3, 0, array2, num4, array3.Length);
num4 += array3.Length;
int num6 = 129 - array3.Length - num3 - 2;
if (num2 < num6)
{
num6 = num2;
}
Array.Copy(array, num, array2, num4, num6);
num4 += num6;
num += num6;
num2 -= num6;
if (num4 < 126)
{
byte[] array4 = new byte[126 - num4];
new Random().NextBytes(array4);
Array.Copy(array4, 0, array2, num4, array4.Length);
num4 += array4.Length;
}
byte[] array5 = SHA1.Create().ComputeHash(array2, num5, array2.Length - num5);
Array.Copy(array5, 0, array2, 0, array5.Length);
list2.AddRange(BigInt.PowMod(array2, this._privateExponent, this._modulus));
}
return Convert.ToBase64String(list2.ToArray());
}
public SerialKeyInformation DecodeKey(string key)
{
return new SerialKeyInformation(key, this._publicExponent, this._modulus);
}
}