scripts
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A3 RID: 163
|
||||
internal class BlockProcessor
|
||||
{
|
||||
// Token: 0x060008EB RID: 2283 RVA: 0x00023098 File Offset: 0x00021298
|
||||
public BlockProcessor(ICryptoTransform transform)
|
||||
: this(transform, transform.InputBlockSize)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060008EC RID: 2284 RVA: 0x000230A8 File Offset: 0x000212A8
|
||||
public BlockProcessor(ICryptoTransform transform, int blockSize)
|
||||
{
|
||||
this.transform = transform;
|
||||
this.blockSize = blockSize;
|
||||
this.block = new byte[blockSize];
|
||||
}
|
||||
|
||||
// Token: 0x060008ED RID: 2285 RVA: 0x000230D8 File Offset: 0x000212D8
|
||||
~BlockProcessor()
|
||||
{
|
||||
Array.Clear(this.block, 0, this.blockSize);
|
||||
}
|
||||
|
||||
// Token: 0x060008EE RID: 2286 RVA: 0x00023120 File Offset: 0x00021320
|
||||
public void Initialize()
|
||||
{
|
||||
Array.Clear(this.block, 0, this.blockSize);
|
||||
this.blockCount = 0;
|
||||
}
|
||||
|
||||
// Token: 0x060008EF RID: 2287 RVA: 0x0002313C File Offset: 0x0002133C
|
||||
public void Core(byte[] rgb)
|
||||
{
|
||||
this.Core(rgb, 0, rgb.Length);
|
||||
}
|
||||
|
||||
// Token: 0x060008F0 RID: 2288 RVA: 0x0002314C File Offset: 0x0002134C
|
||||
public void Core(byte[] rgb, int ib, int cb)
|
||||
{
|
||||
int num = Math.Min(this.blockSize - this.blockCount, cb);
|
||||
Buffer.BlockCopy(rgb, ib, this.block, this.blockCount, num);
|
||||
this.blockCount += num;
|
||||
if (this.blockCount == this.blockSize)
|
||||
{
|
||||
this.transform.TransformBlock(this.block, 0, this.blockSize, this.block, 0);
|
||||
int num2 = (cb - num) / this.blockSize;
|
||||
for (int i = 0; i < num2; i++)
|
||||
{
|
||||
this.transform.TransformBlock(rgb, num + ib, this.blockSize, this.block, 0);
|
||||
num += this.blockSize;
|
||||
}
|
||||
this.blockCount = cb - num;
|
||||
if (this.blockCount > 0)
|
||||
{
|
||||
Buffer.BlockCopy(rgb, num + ib, this.block, 0, this.blockCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008F1 RID: 2289 RVA: 0x00023230 File Offset: 0x00021430
|
||||
public byte[] Final()
|
||||
{
|
||||
return this.transform.TransformFinalBlock(this.block, 0, this.blockCount);
|
||||
}
|
||||
|
||||
// Token: 0x040001DB RID: 475
|
||||
private ICryptoTransform transform;
|
||||
|
||||
// Token: 0x040001DC RID: 476
|
||||
private byte[] block;
|
||||
|
||||
// Token: 0x040001DD RID: 477
|
||||
private int blockSize;
|
||||
|
||||
// Token: 0x040001DE RID: 478
|
||||
private int blockCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,642 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A1 RID: 161
|
||||
internal sealed class CryptoConvert
|
||||
{
|
||||
// Token: 0x060008CC RID: 2252 RVA: 0x00021F80 File Offset: 0x00020180
|
||||
private CryptoConvert()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060008CD RID: 2253 RVA: 0x00021F88 File Offset: 0x00020188
|
||||
private static int ToInt32LE(byte[] bytes, int offset)
|
||||
{
|
||||
return ((int)bytes[offset + 3] << 24) | ((int)bytes[offset + 2] << 16) | ((int)bytes[offset + 1] << 8) | (int)bytes[offset];
|
||||
}
|
||||
|
||||
// Token: 0x060008CE RID: 2254 RVA: 0x00021FA8 File Offset: 0x000201A8
|
||||
private static uint ToUInt32LE(byte[] bytes, int offset)
|
||||
{
|
||||
return (uint)(((int)bytes[offset + 3] << 24) | ((int)bytes[offset + 2] << 16) | ((int)bytes[offset + 1] << 8) | (int)bytes[offset]);
|
||||
}
|
||||
|
||||
// Token: 0x060008CF RID: 2255 RVA: 0x00021FC8 File Offset: 0x000201C8
|
||||
private static byte[] GetBytesLE(int val)
|
||||
{
|
||||
return new byte[]
|
||||
{
|
||||
(byte)(val & 255),
|
||||
(byte)((val >> 8) & 255),
|
||||
(byte)((val >> 16) & 255),
|
||||
(byte)((val >> 24) & 255)
|
||||
};
|
||||
}
|
||||
|
||||
// Token: 0x060008D0 RID: 2256 RVA: 0x00022010 File Offset: 0x00020210
|
||||
private static byte[] Trim(byte[] array)
|
||||
{
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (array[i] != 0)
|
||||
{
|
||||
byte[] array2 = new byte[array.Length - i];
|
||||
Buffer.BlockCopy(array, i, array2, 0, array2.Length);
|
||||
return array2;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x060008D1 RID: 2257 RVA: 0x00022054 File Offset: 0x00020254
|
||||
public static RSA FromCapiPrivateKeyBlob(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPrivateKeyBlob(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008D2 RID: 2258 RVA: 0x00022060 File Offset: 0x00020260
|
||||
public static RSA FromCapiPrivateKeyBlob(byte[] blob, int offset)
|
||||
{
|
||||
if (blob == null)
|
||||
{
|
||||
throw new ArgumentNullException("blob");
|
||||
}
|
||||
if (offset >= blob.Length)
|
||||
{
|
||||
throw new ArgumentException("blob is too small.");
|
||||
}
|
||||
RSAParameters rsaparameters = default(RSAParameters);
|
||||
try
|
||||
{
|
||||
if (blob[offset] != 7 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || CryptoConvert.ToUInt32LE(blob, offset + 8) != 843141970U)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob header");
|
||||
}
|
||||
int num = CryptoConvert.ToInt32LE(blob, offset + 12);
|
||||
byte[] array = new byte[4];
|
||||
Buffer.BlockCopy(blob, offset + 16, array, 0, 4);
|
||||
Array.Reverse(array);
|
||||
rsaparameters.Exponent = CryptoConvert.Trim(array);
|
||||
int num2 = offset + 20;
|
||||
int num3 = num >> 3;
|
||||
rsaparameters.Modulus = new byte[num3];
|
||||
Buffer.BlockCopy(blob, num2, rsaparameters.Modulus, 0, num3);
|
||||
Array.Reverse(rsaparameters.Modulus);
|
||||
num2 += num3;
|
||||
int num4 = num3 >> 1;
|
||||
rsaparameters.P = new byte[num4];
|
||||
Buffer.BlockCopy(blob, num2, rsaparameters.P, 0, num4);
|
||||
Array.Reverse(rsaparameters.P);
|
||||
num2 += num4;
|
||||
rsaparameters.Q = new byte[num4];
|
||||
Buffer.BlockCopy(blob, num2, rsaparameters.Q, 0, num4);
|
||||
Array.Reverse(rsaparameters.Q);
|
||||
num2 += num4;
|
||||
rsaparameters.DP = new byte[num4];
|
||||
Buffer.BlockCopy(blob, num2, rsaparameters.DP, 0, num4);
|
||||
Array.Reverse(rsaparameters.DP);
|
||||
num2 += num4;
|
||||
rsaparameters.DQ = new byte[num4];
|
||||
Buffer.BlockCopy(blob, num2, rsaparameters.DQ, 0, num4);
|
||||
Array.Reverse(rsaparameters.DQ);
|
||||
num2 += num4;
|
||||
rsaparameters.InverseQ = new byte[num4];
|
||||
Buffer.BlockCopy(blob, num2, rsaparameters.InverseQ, 0, num4);
|
||||
Array.Reverse(rsaparameters.InverseQ);
|
||||
num2 += num4;
|
||||
rsaparameters.D = new byte[num3];
|
||||
if (num2 + num3 + offset <= blob.Length)
|
||||
{
|
||||
Buffer.BlockCopy(blob, num2, rsaparameters.D, 0, num3);
|
||||
Array.Reverse(rsaparameters.D);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob.", ex);
|
||||
}
|
||||
RSA rsa = RSA.Create();
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
return rsa;
|
||||
}
|
||||
|
||||
// Token: 0x060008D3 RID: 2259 RVA: 0x000222C4 File Offset: 0x000204C4
|
||||
public static DSA FromCapiPrivateKeyBlobDSA(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPrivateKeyBlobDSA(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008D4 RID: 2260 RVA: 0x000222D0 File Offset: 0x000204D0
|
||||
public static DSA FromCapiPrivateKeyBlobDSA(byte[] blob, int offset)
|
||||
{
|
||||
if (blob == null)
|
||||
{
|
||||
throw new ArgumentNullException("blob");
|
||||
}
|
||||
if (offset >= blob.Length)
|
||||
{
|
||||
throw new ArgumentException("blob is too small.");
|
||||
}
|
||||
DSAParameters dsaparameters = default(DSAParameters);
|
||||
try
|
||||
{
|
||||
if (blob[offset] != 7 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || CryptoConvert.ToUInt32LE(blob, offset + 8) != 844321604U)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob header");
|
||||
}
|
||||
int num = CryptoConvert.ToInt32LE(blob, offset + 12);
|
||||
int num2 = num >> 3;
|
||||
int num3 = offset + 16;
|
||||
dsaparameters.P = new byte[num2];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.P, 0, num2);
|
||||
Array.Reverse(dsaparameters.P);
|
||||
num3 += num2;
|
||||
dsaparameters.Q = new byte[20];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.Q, 0, 20);
|
||||
Array.Reverse(dsaparameters.Q);
|
||||
num3 += 20;
|
||||
dsaparameters.G = new byte[num2];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.G, 0, num2);
|
||||
Array.Reverse(dsaparameters.G);
|
||||
num3 += num2;
|
||||
dsaparameters.X = new byte[20];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.X, 0, 20);
|
||||
Array.Reverse(dsaparameters.X);
|
||||
num3 += 20;
|
||||
dsaparameters.Counter = CryptoConvert.ToInt32LE(blob, num3);
|
||||
num3 += 4;
|
||||
dsaparameters.Seed = new byte[20];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.Seed, 0, 20);
|
||||
Array.Reverse(dsaparameters.Seed);
|
||||
num3 += 20;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob.", ex);
|
||||
}
|
||||
DSA dsa = DSA.Create();
|
||||
dsa.ImportParameters(dsaparameters);
|
||||
return dsa;
|
||||
}
|
||||
|
||||
// Token: 0x060008D5 RID: 2261 RVA: 0x000224A8 File Offset: 0x000206A8
|
||||
public static byte[] ToCapiPrivateKeyBlob(RSA rsa)
|
||||
{
|
||||
RSAParameters rsaparameters = rsa.ExportParameters(true);
|
||||
int num = rsaparameters.Modulus.Length;
|
||||
byte[] array = new byte[20 + (num << 2) + (num >> 1)];
|
||||
array[0] = 7;
|
||||
array[1] = 2;
|
||||
array[5] = 36;
|
||||
array[8] = 82;
|
||||
array[9] = 83;
|
||||
array[10] = 65;
|
||||
array[11] = 50;
|
||||
byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
|
||||
array[12] = bytesLE[0];
|
||||
array[13] = bytesLE[1];
|
||||
array[14] = bytesLE[2];
|
||||
array[15] = bytesLE[3];
|
||||
int num2 = 16;
|
||||
int i = rsaparameters.Exponent.Length;
|
||||
while (i > 0)
|
||||
{
|
||||
array[num2++] = rsaparameters.Exponent[--i];
|
||||
}
|
||||
num2 = 20;
|
||||
byte[] array2 = rsaparameters.Modulus;
|
||||
int num3 = array2.Length;
|
||||
Array.Reverse(array2, 0, num3);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num3);
|
||||
num2 += num3;
|
||||
array2 = rsaparameters.P;
|
||||
num3 = array2.Length;
|
||||
Array.Reverse(array2, 0, num3);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num3);
|
||||
num2 += num3;
|
||||
array2 = rsaparameters.Q;
|
||||
num3 = array2.Length;
|
||||
Array.Reverse(array2, 0, num3);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num3);
|
||||
num2 += num3;
|
||||
array2 = rsaparameters.DP;
|
||||
num3 = array2.Length;
|
||||
Array.Reverse(array2, 0, num3);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num3);
|
||||
num2 += num3;
|
||||
array2 = rsaparameters.DQ;
|
||||
num3 = array2.Length;
|
||||
Array.Reverse(array2, 0, num3);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num3);
|
||||
num2 += num3;
|
||||
array2 = rsaparameters.InverseQ;
|
||||
num3 = array2.Length;
|
||||
Array.Reverse(array2, 0, num3);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num3);
|
||||
num2 += num3;
|
||||
array2 = rsaparameters.D;
|
||||
num3 = array2.Length;
|
||||
Array.Reverse(array2, 0, num3);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num3);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060008D6 RID: 2262 RVA: 0x00022690 File Offset: 0x00020890
|
||||
public static byte[] ToCapiPrivateKeyBlob(DSA dsa)
|
||||
{
|
||||
DSAParameters dsaparameters = dsa.ExportParameters(true);
|
||||
int num = dsaparameters.P.Length;
|
||||
byte[] array = new byte[16 + num + 20 + num + 20 + 4 + 20];
|
||||
array[0] = 7;
|
||||
array[1] = 2;
|
||||
array[5] = 34;
|
||||
array[8] = 68;
|
||||
array[9] = 83;
|
||||
array[10] = 83;
|
||||
array[11] = 50;
|
||||
byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
|
||||
array[12] = bytesLE[0];
|
||||
array[13] = bytesLE[1];
|
||||
array[14] = bytesLE[2];
|
||||
array[15] = bytesLE[3];
|
||||
int num2 = 16;
|
||||
byte[] array2 = dsaparameters.P;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num);
|
||||
num2 += num;
|
||||
array2 = dsaparameters.Q;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, 20);
|
||||
num2 += 20;
|
||||
array2 = dsaparameters.G;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num);
|
||||
num2 += num;
|
||||
array2 = dsaparameters.X;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, 20);
|
||||
num2 += 20;
|
||||
Buffer.BlockCopy(CryptoConvert.GetBytesLE(dsaparameters.Counter), 0, array, num2, 4);
|
||||
num2 += 4;
|
||||
array2 = dsaparameters.Seed;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, 20);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060008D7 RID: 2263 RVA: 0x000227DC File Offset: 0x000209DC
|
||||
public static RSA FromCapiPublicKeyBlob(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPublicKeyBlob(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008D8 RID: 2264 RVA: 0x000227E8 File Offset: 0x000209E8
|
||||
public static RSA FromCapiPublicKeyBlob(byte[] blob, int offset)
|
||||
{
|
||||
if (blob == null)
|
||||
{
|
||||
throw new ArgumentNullException("blob");
|
||||
}
|
||||
if (offset >= blob.Length)
|
||||
{
|
||||
throw new ArgumentException("blob is too small.");
|
||||
}
|
||||
RSA rsa2;
|
||||
try
|
||||
{
|
||||
if (blob[offset] != 6 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || CryptoConvert.ToUInt32LE(blob, offset + 8) != 826364754U)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob header");
|
||||
}
|
||||
int num = CryptoConvert.ToInt32LE(blob, offset + 12);
|
||||
RSAParameters rsaparameters = default(RSAParameters);
|
||||
rsaparameters.Exponent = new byte[3];
|
||||
rsaparameters.Exponent[0] = blob[offset + 18];
|
||||
rsaparameters.Exponent[1] = blob[offset + 17];
|
||||
rsaparameters.Exponent[2] = blob[offset + 16];
|
||||
int num2 = offset + 20;
|
||||
int num3 = num >> 3;
|
||||
rsaparameters.Modulus = new byte[num3];
|
||||
Buffer.BlockCopy(blob, num2, rsaparameters.Modulus, 0, num3);
|
||||
Array.Reverse(rsaparameters.Modulus);
|
||||
RSA rsa = RSA.Create();
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
rsa2 = rsa;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob.", ex);
|
||||
}
|
||||
return rsa2;
|
||||
}
|
||||
|
||||
// Token: 0x060008D9 RID: 2265 RVA: 0x00022930 File Offset: 0x00020B30
|
||||
public static DSA FromCapiPublicKeyBlobDSA(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPublicKeyBlobDSA(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008DA RID: 2266 RVA: 0x0002293C File Offset: 0x00020B3C
|
||||
public static DSA FromCapiPublicKeyBlobDSA(byte[] blob, int offset)
|
||||
{
|
||||
if (blob == null)
|
||||
{
|
||||
throw new ArgumentNullException("blob");
|
||||
}
|
||||
if (offset >= blob.Length)
|
||||
{
|
||||
throw new ArgumentException("blob is too small.");
|
||||
}
|
||||
DSA dsa2;
|
||||
try
|
||||
{
|
||||
if (blob[offset] != 6 || blob[offset + 1] != 2 || blob[offset + 2] != 0 || blob[offset + 3] != 0 || CryptoConvert.ToUInt32LE(blob, offset + 8) != 827544388U)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob header");
|
||||
}
|
||||
int num = CryptoConvert.ToInt32LE(blob, offset + 12);
|
||||
DSAParameters dsaparameters = default(DSAParameters);
|
||||
int num2 = num >> 3;
|
||||
int num3 = offset + 16;
|
||||
dsaparameters.P = new byte[num2];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.P, 0, num2);
|
||||
Array.Reverse(dsaparameters.P);
|
||||
num3 += num2;
|
||||
dsaparameters.Q = new byte[20];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.Q, 0, 20);
|
||||
Array.Reverse(dsaparameters.Q);
|
||||
num3 += 20;
|
||||
dsaparameters.G = new byte[num2];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.G, 0, num2);
|
||||
Array.Reverse(dsaparameters.G);
|
||||
num3 += num2;
|
||||
dsaparameters.Y = new byte[num2];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.Y, 0, num2);
|
||||
Array.Reverse(dsaparameters.Y);
|
||||
num3 += num2;
|
||||
dsaparameters.Counter = CryptoConvert.ToInt32LE(blob, num3);
|
||||
num3 += 4;
|
||||
dsaparameters.Seed = new byte[20];
|
||||
Buffer.BlockCopy(blob, num3, dsaparameters.Seed, 0, 20);
|
||||
Array.Reverse(dsaparameters.Seed);
|
||||
num3 += 20;
|
||||
DSA dsa = DSA.Create();
|
||||
dsa.ImportParameters(dsaparameters);
|
||||
dsa2 = dsa;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob.", ex);
|
||||
}
|
||||
return dsa2;
|
||||
}
|
||||
|
||||
// Token: 0x060008DB RID: 2267 RVA: 0x00022B18 File Offset: 0x00020D18
|
||||
public static byte[] ToCapiPublicKeyBlob(RSA rsa)
|
||||
{
|
||||
RSAParameters rsaparameters = rsa.ExportParameters(false);
|
||||
int num = rsaparameters.Modulus.Length;
|
||||
byte[] array = new byte[20 + num];
|
||||
array[0] = 6;
|
||||
array[1] = 2;
|
||||
array[5] = 36;
|
||||
array[8] = 82;
|
||||
array[9] = 83;
|
||||
array[10] = 65;
|
||||
array[11] = 49;
|
||||
byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
|
||||
array[12] = bytesLE[0];
|
||||
array[13] = bytesLE[1];
|
||||
array[14] = bytesLE[2];
|
||||
array[15] = bytesLE[3];
|
||||
int num2 = 16;
|
||||
int i = rsaparameters.Exponent.Length;
|
||||
while (i > 0)
|
||||
{
|
||||
array[num2++] = rsaparameters.Exponent[--i];
|
||||
}
|
||||
num2 = 20;
|
||||
byte[] modulus = rsaparameters.Modulus;
|
||||
int num3 = modulus.Length;
|
||||
Array.Reverse(modulus, 0, num3);
|
||||
Buffer.BlockCopy(modulus, 0, array, num2, num3);
|
||||
num2 += num3;
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060008DC RID: 2268 RVA: 0x00022BF0 File Offset: 0x00020DF0
|
||||
public static byte[] ToCapiPublicKeyBlob(DSA dsa)
|
||||
{
|
||||
DSAParameters dsaparameters = dsa.ExportParameters(false);
|
||||
int num = dsaparameters.P.Length;
|
||||
byte[] array = new byte[16 + num + 20 + num + num + 4 + 20];
|
||||
array[0] = 6;
|
||||
array[1] = 2;
|
||||
array[5] = 34;
|
||||
array[8] = 68;
|
||||
array[9] = 83;
|
||||
array[10] = 83;
|
||||
array[11] = 49;
|
||||
byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
|
||||
array[12] = bytesLE[0];
|
||||
array[13] = bytesLE[1];
|
||||
array[14] = bytesLE[2];
|
||||
array[15] = bytesLE[3];
|
||||
int num2 = 16;
|
||||
byte[] array2 = dsaparameters.P;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num);
|
||||
num2 += num;
|
||||
array2 = dsaparameters.Q;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, 20);
|
||||
num2 += 20;
|
||||
array2 = dsaparameters.G;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num);
|
||||
num2 += num;
|
||||
array2 = dsaparameters.Y;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, num);
|
||||
num2 += num;
|
||||
Buffer.BlockCopy(CryptoConvert.GetBytesLE(dsaparameters.Counter), 0, array, num2, 4);
|
||||
num2 += 4;
|
||||
array2 = dsaparameters.Seed;
|
||||
Array.Reverse(array2);
|
||||
Buffer.BlockCopy(array2, 0, array, num2, 20);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060008DD RID: 2269 RVA: 0x00022D38 File Offset: 0x00020F38
|
||||
public static RSA FromCapiKeyBlob(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiKeyBlob(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008DE RID: 2270 RVA: 0x00022D44 File Offset: 0x00020F44
|
||||
public static RSA FromCapiKeyBlob(byte[] blob, int offset)
|
||||
{
|
||||
if (blob == null)
|
||||
{
|
||||
throw new ArgumentNullException("blob");
|
||||
}
|
||||
if (offset >= blob.Length)
|
||||
{
|
||||
throw new ArgumentException("blob is too small.");
|
||||
}
|
||||
byte b = blob[offset];
|
||||
if (b == 6)
|
||||
{
|
||||
return CryptoConvert.FromCapiPublicKeyBlob(blob, offset);
|
||||
}
|
||||
if (b != 7)
|
||||
{
|
||||
if (b == 0)
|
||||
{
|
||||
if (blob[offset + 12] == 6)
|
||||
{
|
||||
return CryptoConvert.FromCapiPublicKeyBlob(blob, offset + 12);
|
||||
}
|
||||
}
|
||||
throw new CryptographicException("Unknown blob format.");
|
||||
}
|
||||
return CryptoConvert.FromCapiPrivateKeyBlob(blob, offset);
|
||||
}
|
||||
|
||||
// Token: 0x060008DF RID: 2271 RVA: 0x00022DCC File Offset: 0x00020FCC
|
||||
public static DSA FromCapiKeyBlobDSA(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiKeyBlobDSA(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x060008E0 RID: 2272 RVA: 0x00022DD8 File Offset: 0x00020FD8
|
||||
public static DSA FromCapiKeyBlobDSA(byte[] blob, int offset)
|
||||
{
|
||||
if (blob == null)
|
||||
{
|
||||
throw new ArgumentNullException("blob");
|
||||
}
|
||||
if (offset >= blob.Length)
|
||||
{
|
||||
throw new ArgumentException("blob is too small.");
|
||||
}
|
||||
byte b = blob[offset];
|
||||
if (b == 6)
|
||||
{
|
||||
return CryptoConvert.FromCapiPublicKeyBlobDSA(blob, offset);
|
||||
}
|
||||
if (b != 7)
|
||||
{
|
||||
throw new CryptographicException("Unknown blob format.");
|
||||
}
|
||||
return CryptoConvert.FromCapiPrivateKeyBlobDSA(blob, offset);
|
||||
}
|
||||
|
||||
// Token: 0x060008E1 RID: 2273 RVA: 0x00022E3C File Offset: 0x0002103C
|
||||
public static byte[] ToCapiKeyBlob(AsymmetricAlgorithm keypair, bool includePrivateKey)
|
||||
{
|
||||
if (keypair == null)
|
||||
{
|
||||
throw new ArgumentNullException("keypair");
|
||||
}
|
||||
if (keypair is RSA)
|
||||
{
|
||||
return CryptoConvert.ToCapiKeyBlob((RSA)keypair, includePrivateKey);
|
||||
}
|
||||
if (keypair is DSA)
|
||||
{
|
||||
return CryptoConvert.ToCapiKeyBlob((DSA)keypair, includePrivateKey);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x060008E2 RID: 2274 RVA: 0x00022E8C File Offset: 0x0002108C
|
||||
public static byte[] ToCapiKeyBlob(RSA rsa, bool includePrivateKey)
|
||||
{
|
||||
if (rsa == null)
|
||||
{
|
||||
throw new ArgumentNullException("rsa");
|
||||
}
|
||||
if (includePrivateKey)
|
||||
{
|
||||
return CryptoConvert.ToCapiPrivateKeyBlob(rsa);
|
||||
}
|
||||
return CryptoConvert.ToCapiPublicKeyBlob(rsa);
|
||||
}
|
||||
|
||||
// Token: 0x060008E3 RID: 2275 RVA: 0x00022EC0 File Offset: 0x000210C0
|
||||
public static byte[] ToCapiKeyBlob(DSA dsa, bool includePrivateKey)
|
||||
{
|
||||
if (dsa == null)
|
||||
{
|
||||
throw new ArgumentNullException("dsa");
|
||||
}
|
||||
if (includePrivateKey)
|
||||
{
|
||||
return CryptoConvert.ToCapiPrivateKeyBlob(dsa);
|
||||
}
|
||||
return CryptoConvert.ToCapiPublicKeyBlob(dsa);
|
||||
}
|
||||
|
||||
// Token: 0x060008E4 RID: 2276 RVA: 0x00022EF4 File Offset: 0x000210F4
|
||||
public static string ToHex(byte[] input)
|
||||
{
|
||||
if (input == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder(input.Length * 2);
|
||||
foreach (byte b in input)
|
||||
{
|
||||
stringBuilder.Append(b.ToString("X2", CultureInfo.InvariantCulture));
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x060008E5 RID: 2277 RVA: 0x00022F4C File Offset: 0x0002114C
|
||||
private static byte FromHexChar(char c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'f')
|
||||
{
|
||||
return (byte)(c - 'a' + '\n');
|
||||
}
|
||||
if (c >= 'A' && c <= 'F')
|
||||
{
|
||||
return (byte)(c - 'A' + '\n');
|
||||
}
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
return (byte)(c - '0');
|
||||
}
|
||||
throw new ArgumentException("invalid hex char");
|
||||
}
|
||||
|
||||
// Token: 0x060008E6 RID: 2278 RVA: 0x00022FAC File Offset: 0x000211AC
|
||||
public static byte[] FromHex(string hex)
|
||||
{
|
||||
if (hex == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if ((hex.Length & 1) == 1)
|
||||
{
|
||||
throw new ArgumentException("Length must be a multiple of 2");
|
||||
}
|
||||
byte[] array = new byte[hex.Length >> 1];
|
||||
int i = 0;
|
||||
int num = 0;
|
||||
while (i < array.Length)
|
||||
{
|
||||
array[i] = (byte)(CryptoConvert.FromHexChar(hex[num++]) << 4);
|
||||
byte[] array2 = array;
|
||||
int num2 = i++;
|
||||
array2[num2] += CryptoConvert.FromHexChar(hex[num++]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,509 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using Mono.Math;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A4 RID: 164
|
||||
internal class DSAManaged : DSA
|
||||
{
|
||||
// Token: 0x060008F2 RID: 2290 RVA: 0x0002324C File Offset: 0x0002144C
|
||||
public DSAManaged()
|
||||
: this(1024)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060008F3 RID: 2291 RVA: 0x0002325C File Offset: 0x0002145C
|
||||
public DSAManaged(int dwKeySize)
|
||||
{
|
||||
this.KeySizeValue = dwKeySize;
|
||||
this.LegalKeySizesValue = new KeySizes[1];
|
||||
this.LegalKeySizesValue[0] = new KeySizes(512, 1024, 64);
|
||||
}
|
||||
|
||||
// Token: 0x14000001 RID: 1
|
||||
// (add) Token: 0x060008F4 RID: 2292 RVA: 0x0002329C File Offset: 0x0002149C
|
||||
// (remove) Token: 0x060008F5 RID: 2293 RVA: 0x000232B8 File Offset: 0x000214B8
|
||||
public event DSAManaged.KeyGeneratedEventHandler KeyGenerated;
|
||||
|
||||
// Token: 0x060008F6 RID: 2294 RVA: 0x000232D4 File Offset: 0x000214D4
|
||||
~DSAManaged()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
// Token: 0x060008F7 RID: 2295 RVA: 0x00023310 File Offset: 0x00021510
|
||||
private void Generate()
|
||||
{
|
||||
this.GenerateParams(base.KeySize);
|
||||
this.GenerateKeyPair();
|
||||
this.keypairGenerated = true;
|
||||
if (this.KeyGenerated != null)
|
||||
{
|
||||
this.KeyGenerated(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008F8 RID: 2296 RVA: 0x00023350 File Offset: 0x00021550
|
||||
private void GenerateKeyPair()
|
||||
{
|
||||
this.x = BigInteger.GenerateRandom(160);
|
||||
while (this.x == 0U || this.x >= this.q)
|
||||
{
|
||||
this.x.Randomize();
|
||||
}
|
||||
this.y = this.g.ModPow(this.x, this.p);
|
||||
}
|
||||
|
||||
// Token: 0x060008F9 RID: 2297 RVA: 0x000233C4 File Offset: 0x000215C4
|
||||
private void add(byte[] a, byte[] b, int value)
|
||||
{
|
||||
uint num = (uint)((int)(b[b.Length - 1] & byte.MaxValue) + value);
|
||||
a[b.Length - 1] = (byte)num;
|
||||
num >>= 8;
|
||||
for (int i = b.Length - 2; i >= 0; i--)
|
||||
{
|
||||
num += (uint)(b[i] & byte.MaxValue);
|
||||
a[i] = (byte)num;
|
||||
num >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008FA RID: 2298 RVA: 0x0002341C File Offset: 0x0002161C
|
||||
private void GenerateParams(int keyLength)
|
||||
{
|
||||
byte[] array = new byte[20];
|
||||
byte[] array2 = new byte[20];
|
||||
byte[] array3 = new byte[20];
|
||||
byte[] array4 = new byte[20];
|
||||
SHA1 sha = SHA1.Create();
|
||||
int num = (keyLength - 1) / 160;
|
||||
byte[] array5 = new byte[keyLength / 8];
|
||||
bool flag = false;
|
||||
while (!flag)
|
||||
{
|
||||
do
|
||||
{
|
||||
this.Random.GetBytes(array);
|
||||
array2 = sha.ComputeHash(array);
|
||||
Array.Copy(array, 0, array3, 0, array.Length);
|
||||
this.add(array3, array, 1);
|
||||
array3 = sha.ComputeHash(array3);
|
||||
for (int num2 = 0; num2 != array4.Length; num2++)
|
||||
{
|
||||
array4[num2] = array2[num2] ^ array3[num2];
|
||||
}
|
||||
byte[] array6 = array4;
|
||||
int num3 = 0;
|
||||
array6[num3] |= 128;
|
||||
byte[] array7 = array4;
|
||||
int num4 = 19;
|
||||
array7[num4] |= 1;
|
||||
this.q = new BigInteger(array4);
|
||||
}
|
||||
while (!this.q.IsProbablePrime());
|
||||
this.counter = 0;
|
||||
int num5 = 2;
|
||||
while (this.counter < 4096)
|
||||
{
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
this.add(array2, array, num5 + i);
|
||||
array2 = sha.ComputeHash(array2);
|
||||
Array.Copy(array2, 0, array5, array5.Length - (i + 1) * array2.Length, array2.Length);
|
||||
}
|
||||
this.add(array2, array, num5 + num);
|
||||
array2 = sha.ComputeHash(array2);
|
||||
Array.Copy(array2, array2.Length - (array5.Length - num * array2.Length), array5, 0, array5.Length - num * array2.Length);
|
||||
byte[] array8 = array5;
|
||||
int num6 = 0;
|
||||
array8[num6] |= 128;
|
||||
BigInteger bigInteger = new BigInteger(array5);
|
||||
BigInteger bigInteger2 = bigInteger % (this.q * 2);
|
||||
this.p = bigInteger - (bigInteger2 - 1);
|
||||
if (this.p.TestBit((uint)(keyLength - 1)) && this.p.IsProbablePrime())
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
this.counter++;
|
||||
num5 += num + 1;
|
||||
}
|
||||
}
|
||||
BigInteger bigInteger3 = (this.p - 1) / this.q;
|
||||
for (;;)
|
||||
{
|
||||
BigInteger bigInteger4 = BigInteger.GenerateRandom(keyLength);
|
||||
if (!(bigInteger4 <= 1) && !(bigInteger4 >= this.p - 1))
|
||||
{
|
||||
this.g = bigInteger4.ModPow(bigInteger3, this.p);
|
||||
if (!(this.g <= 1))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.seed = new BigInteger(array);
|
||||
this.j = (this.p - 1) / this.q;
|
||||
}
|
||||
|
||||
// Token: 0x170000F2 RID: 242
|
||||
// (get) Token: 0x060008FB RID: 2299 RVA: 0x000236FC File Offset: 0x000218FC
|
||||
private RandomNumberGenerator Random
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.rng == null)
|
||||
{
|
||||
this.rng = RandomNumberGenerator.Create();
|
||||
}
|
||||
return this.rng;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F3 RID: 243
|
||||
// (get) Token: 0x060008FC RID: 2300 RVA: 0x0002371C File Offset: 0x0002191C
|
||||
public override int KeySize
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.keypairGenerated)
|
||||
{
|
||||
return this.p.BitCount();
|
||||
}
|
||||
return base.KeySize;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F4 RID: 244
|
||||
// (get) Token: 0x060008FD RID: 2301 RVA: 0x0002373C File Offset: 0x0002193C
|
||||
public override string KeyExchangeAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F5 RID: 245
|
||||
// (get) Token: 0x060008FE RID: 2302 RVA: 0x00023740 File Offset: 0x00021940
|
||||
public bool PublicOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.keypairGenerated && this.x == null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F6 RID: 246
|
||||
// (get) Token: 0x060008FF RID: 2303 RVA: 0x0002375C File Offset: 0x0002195C
|
||||
public override string SignatureAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return "http://www.w3.org/2000/09/xmldsig#dsa-sha1";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000900 RID: 2304 RVA: 0x00023764 File Offset: 0x00021964
|
||||
private byte[] NormalizeArray(byte[] array)
|
||||
{
|
||||
int num = array.Length % 4;
|
||||
if (num > 0)
|
||||
{
|
||||
byte[] array2 = new byte[array.Length + 4 - num];
|
||||
Array.Copy(array, 0, array2, 4 - num, array.Length);
|
||||
return array2;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000901 RID: 2305 RVA: 0x0002379C File Offset: 0x0002199C
|
||||
public override DSAParameters ExportParameters(bool includePrivateParameters)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (!this.keypairGenerated)
|
||||
{
|
||||
this.Generate();
|
||||
}
|
||||
if (includePrivateParameters && this.x == null)
|
||||
{
|
||||
throw new CryptographicException("no private key to export");
|
||||
}
|
||||
DSAParameters dsaparameters = default(DSAParameters);
|
||||
dsaparameters.P = this.NormalizeArray(this.p.GetBytes());
|
||||
dsaparameters.Q = this.NormalizeArray(this.q.GetBytes());
|
||||
dsaparameters.G = this.NormalizeArray(this.g.GetBytes());
|
||||
dsaparameters.Y = this.NormalizeArray(this.y.GetBytes());
|
||||
if (!this.j_missing)
|
||||
{
|
||||
dsaparameters.J = this.NormalizeArray(this.j.GetBytes());
|
||||
}
|
||||
if (this.seed != 0U)
|
||||
{
|
||||
dsaparameters.Seed = this.NormalizeArray(this.seed.GetBytes());
|
||||
dsaparameters.Counter = this.counter;
|
||||
}
|
||||
if (includePrivateParameters)
|
||||
{
|
||||
byte[] bytes = this.x.GetBytes();
|
||||
if (bytes.Length == 20)
|
||||
{
|
||||
dsaparameters.X = this.NormalizeArray(bytes);
|
||||
}
|
||||
}
|
||||
return dsaparameters;
|
||||
}
|
||||
|
||||
// Token: 0x06000902 RID: 2306 RVA: 0x000238E4 File Offset: 0x00021AE4
|
||||
public override void ImportParameters(DSAParameters parameters)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (parameters.P == null || parameters.Q == null || parameters.G == null)
|
||||
{
|
||||
throw new CryptographicException(Locale.GetText("Missing mandatory DSA parameters (P, Q or G)."));
|
||||
}
|
||||
if (parameters.X == null && parameters.Y == null)
|
||||
{
|
||||
throw new CryptographicException(Locale.GetText("Missing both public (Y) and private (X) keys."));
|
||||
}
|
||||
this.p = new BigInteger(parameters.P);
|
||||
this.q = new BigInteger(parameters.Q);
|
||||
this.g = new BigInteger(parameters.G);
|
||||
if (parameters.X != null)
|
||||
{
|
||||
this.x = new BigInteger(parameters.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.x = null;
|
||||
}
|
||||
if (parameters.Y != null)
|
||||
{
|
||||
this.y = new BigInteger(parameters.Y);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.y = this.g.ModPow(this.x, this.p);
|
||||
}
|
||||
if (parameters.J != null)
|
||||
{
|
||||
this.j = new BigInteger(parameters.J);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.j = (this.p - 1) / this.q;
|
||||
this.j_missing = true;
|
||||
}
|
||||
if (parameters.Seed != null)
|
||||
{
|
||||
this.seed = new BigInteger(parameters.Seed);
|
||||
this.counter = parameters.Counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.seed = 0;
|
||||
}
|
||||
this.keypairGenerated = true;
|
||||
}
|
||||
|
||||
// Token: 0x06000903 RID: 2307 RVA: 0x00023A98 File Offset: 0x00021C98
|
||||
public override byte[] CreateSignature(byte[] rgbHash)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (rgbHash == null)
|
||||
{
|
||||
throw new ArgumentNullException("rgbHash");
|
||||
}
|
||||
if (rgbHash.Length != 20)
|
||||
{
|
||||
throw new CryptographicException("invalid hash length");
|
||||
}
|
||||
if (!this.keypairGenerated)
|
||||
{
|
||||
this.Generate();
|
||||
}
|
||||
if (this.x == null)
|
||||
{
|
||||
throw new CryptographicException("no private key available for signature");
|
||||
}
|
||||
BigInteger bigInteger = new BigInteger(rgbHash);
|
||||
BigInteger bigInteger2 = BigInteger.GenerateRandom(160);
|
||||
while (bigInteger2 >= this.q)
|
||||
{
|
||||
bigInteger2.Randomize();
|
||||
}
|
||||
BigInteger bigInteger3 = this.g.ModPow(bigInteger2, this.p) % this.q;
|
||||
BigInteger bigInteger4 = bigInteger2.ModInverse(this.q) * (bigInteger + this.x * bigInteger3) % this.q;
|
||||
byte[] array = new byte[40];
|
||||
byte[] bytes = bigInteger3.GetBytes();
|
||||
byte[] bytes2 = bigInteger4.GetBytes();
|
||||
int num = 20 - bytes.Length;
|
||||
Array.Copy(bytes, 0, array, num, bytes.Length);
|
||||
num = 40 - bytes2.Length;
|
||||
Array.Copy(bytes2, 0, array, num, bytes2.Length);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000904 RID: 2308 RVA: 0x00023BDC File Offset: 0x00021DDC
|
||||
public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (rgbHash == null)
|
||||
{
|
||||
throw new ArgumentNullException("rgbHash");
|
||||
}
|
||||
if (rgbSignature == null)
|
||||
{
|
||||
throw new ArgumentNullException("rgbSignature");
|
||||
}
|
||||
if (rgbHash.Length != 20)
|
||||
{
|
||||
throw new CryptographicException("invalid hash length");
|
||||
}
|
||||
if (rgbSignature.Length != 40)
|
||||
{
|
||||
throw new CryptographicException("invalid signature length");
|
||||
}
|
||||
if (!this.keypairGenerated)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
BigInteger bigInteger = new BigInteger(rgbHash);
|
||||
byte[] array = new byte[20];
|
||||
Array.Copy(rgbSignature, 0, array, 0, 20);
|
||||
BigInteger bigInteger2 = new BigInteger(array);
|
||||
Array.Copy(rgbSignature, 20, array, 0, 20);
|
||||
BigInteger bigInteger3 = new BigInteger(array);
|
||||
if (bigInteger2 < 0 || this.q <= bigInteger2)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
else if (bigInteger3 < 0 || this.q <= bigInteger3)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
BigInteger bigInteger4 = bigInteger3.ModInverse(this.q);
|
||||
BigInteger bigInteger5 = bigInteger * bigInteger4 % this.q;
|
||||
BigInteger bigInteger6 = bigInteger2 * bigInteger4 % this.q;
|
||||
bigInteger5 = this.g.ModPow(bigInteger5, this.p);
|
||||
bigInteger6 = this.y.ModPow(bigInteger6, this.p);
|
||||
BigInteger bigInteger7 = bigInteger5 * bigInteger6 % this.p % this.q;
|
||||
flag = bigInteger7 == bigInteger2;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new CryptographicException("couldn't compute signature verification");
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000905 RID: 2309 RVA: 0x00023DAC File Offset: 0x00021FAC
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.m_disposed)
|
||||
{
|
||||
if (this.x != null)
|
||||
{
|
||||
this.x.Clear();
|
||||
this.x = null;
|
||||
}
|
||||
if (disposing)
|
||||
{
|
||||
if (this.p != null)
|
||||
{
|
||||
this.p.Clear();
|
||||
this.p = null;
|
||||
}
|
||||
if (this.q != null)
|
||||
{
|
||||
this.q.Clear();
|
||||
this.q = null;
|
||||
}
|
||||
if (this.g != null)
|
||||
{
|
||||
this.g.Clear();
|
||||
this.g = null;
|
||||
}
|
||||
if (this.j != null)
|
||||
{
|
||||
this.j.Clear();
|
||||
this.j = null;
|
||||
}
|
||||
if (this.seed != null)
|
||||
{
|
||||
this.seed.Clear();
|
||||
this.seed = null;
|
||||
}
|
||||
if (this.y != null)
|
||||
{
|
||||
this.y.Clear();
|
||||
this.y = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.m_disposed = true;
|
||||
}
|
||||
|
||||
// Token: 0x040001DF RID: 479
|
||||
private const int defaultKeySize = 1024;
|
||||
|
||||
// Token: 0x040001E0 RID: 480
|
||||
private bool keypairGenerated;
|
||||
|
||||
// Token: 0x040001E1 RID: 481
|
||||
private bool m_disposed;
|
||||
|
||||
// Token: 0x040001E2 RID: 482
|
||||
private BigInteger p;
|
||||
|
||||
// Token: 0x040001E3 RID: 483
|
||||
private BigInteger q;
|
||||
|
||||
// Token: 0x040001E4 RID: 484
|
||||
private BigInteger g;
|
||||
|
||||
// Token: 0x040001E5 RID: 485
|
||||
private BigInteger x;
|
||||
|
||||
// Token: 0x040001E6 RID: 486
|
||||
private BigInteger y;
|
||||
|
||||
// Token: 0x040001E7 RID: 487
|
||||
private BigInteger j;
|
||||
|
||||
// Token: 0x040001E8 RID: 488
|
||||
private BigInteger seed;
|
||||
|
||||
// Token: 0x040001E9 RID: 489
|
||||
private int counter;
|
||||
|
||||
// Token: 0x040001EA RID: 490
|
||||
private bool j_missing;
|
||||
|
||||
// Token: 0x040001EB RID: 491
|
||||
private RandomNumberGenerator rng;
|
||||
|
||||
// Token: 0x020006C4 RID: 1732
|
||||
// (Invoke) Token: 0x06004198 RID: 16792
|
||||
public delegate void KeyGeneratedEventHandler(object sender, EventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A5 RID: 165
|
||||
internal class HMACAlgorithm
|
||||
{
|
||||
// Token: 0x06000906 RID: 2310 RVA: 0x00023EC8 File Offset: 0x000220C8
|
||||
public HMACAlgorithm(string algoName)
|
||||
{
|
||||
this.CreateHash(algoName);
|
||||
}
|
||||
|
||||
// Token: 0x06000907 RID: 2311 RVA: 0x00023ED8 File Offset: 0x000220D8
|
||||
~HMACAlgorithm()
|
||||
{
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
// Token: 0x06000908 RID: 2312 RVA: 0x00023F14 File Offset: 0x00022114
|
||||
private void CreateHash(string algoName)
|
||||
{
|
||||
this.algo = HashAlgorithm.Create(algoName);
|
||||
this.hashName = algoName;
|
||||
this.block = new BlockProcessor(this.algo, 8);
|
||||
}
|
||||
|
||||
// Token: 0x06000909 RID: 2313 RVA: 0x00023F3C File Offset: 0x0002213C
|
||||
public void Dispose()
|
||||
{
|
||||
if (this.key != null)
|
||||
{
|
||||
Array.Clear(this.key, 0, this.key.Length);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F7 RID: 247
|
||||
// (get) Token: 0x0600090A RID: 2314 RVA: 0x00023F60 File Offset: 0x00022160
|
||||
public HashAlgorithm Algo
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.algo;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F8 RID: 248
|
||||
// (get) Token: 0x0600090B RID: 2315 RVA: 0x00023F68 File Offset: 0x00022168
|
||||
// (set) Token: 0x0600090C RID: 2316 RVA: 0x00023F70 File Offset: 0x00022170
|
||||
public string HashName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.hashName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.CreateHash(value);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000F9 RID: 249
|
||||
// (get) Token: 0x0600090D RID: 2317 RVA: 0x00023F7C File Offset: 0x0002217C
|
||||
// (set) Token: 0x0600090E RID: 2318 RVA: 0x00023F84 File Offset: 0x00022184
|
||||
public byte[] Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null && value.Length > 64)
|
||||
{
|
||||
this.key = this.algo.ComputeHash(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.key = (byte[])value.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600090F RID: 2319 RVA: 0x00023FCC File Offset: 0x000221CC
|
||||
public void Initialize()
|
||||
{
|
||||
this.hash = null;
|
||||
this.block.Initialize();
|
||||
byte[] array = this.KeySetup(this.key, 54);
|
||||
this.algo.Initialize();
|
||||
this.block.Core(array);
|
||||
Array.Clear(array, 0, array.Length);
|
||||
}
|
||||
|
||||
// Token: 0x06000910 RID: 2320 RVA: 0x0002401C File Offset: 0x0002221C
|
||||
private byte[] KeySetup(byte[] key, byte padding)
|
||||
{
|
||||
byte[] array = new byte[64];
|
||||
for (int i = 0; i < key.Length; i++)
|
||||
{
|
||||
array[i] = key[i] ^ padding;
|
||||
}
|
||||
for (int j = key.Length; j < 64; j++)
|
||||
{
|
||||
array[j] = padding;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000911 RID: 2321 RVA: 0x00024068 File Offset: 0x00022268
|
||||
public void Core(byte[] rgb, int ib, int cb)
|
||||
{
|
||||
this.block.Core(rgb, ib, cb);
|
||||
}
|
||||
|
||||
// Token: 0x06000912 RID: 2322 RVA: 0x00024078 File Offset: 0x00022278
|
||||
public byte[] Final()
|
||||
{
|
||||
this.block.Final();
|
||||
byte[] array = this.algo.Hash;
|
||||
byte[] array2 = this.KeySetup(this.key, 92);
|
||||
this.algo.Initialize();
|
||||
this.algo.TransformBlock(array2, 0, array2.Length, array2, 0);
|
||||
this.algo.TransformFinalBlock(array, 0, array.Length);
|
||||
this.hash = this.algo.Hash;
|
||||
this.algo.Clear();
|
||||
Array.Clear(array2, 0, array2.Length);
|
||||
Array.Clear(array, 0, array.Length);
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
// Token: 0x040001ED RID: 493
|
||||
private byte[] key;
|
||||
|
||||
// Token: 0x040001EE RID: 494
|
||||
private byte[] hash;
|
||||
|
||||
// Token: 0x040001EF RID: 495
|
||||
private HashAlgorithm algo;
|
||||
|
||||
// Token: 0x040001F0 RID: 496
|
||||
private string hashName;
|
||||
|
||||
// Token: 0x040001F1 RID: 497
|
||||
private BlockProcessor block;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A2 RID: 162
|
||||
internal sealed class KeyBuilder
|
||||
{
|
||||
// Token: 0x060008E7 RID: 2279 RVA: 0x00023034 File Offset: 0x00021234
|
||||
private KeyBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x170000F1 RID: 241
|
||||
// (get) Token: 0x060008E8 RID: 2280 RVA: 0x0002303C File Offset: 0x0002123C
|
||||
private static RandomNumberGenerator Rng
|
||||
{
|
||||
get
|
||||
{
|
||||
if (KeyBuilder.rng == null)
|
||||
{
|
||||
KeyBuilder.rng = RandomNumberGenerator.Create();
|
||||
}
|
||||
return KeyBuilder.rng;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060008E9 RID: 2281 RVA: 0x00023058 File Offset: 0x00021258
|
||||
public static byte[] Key(int size)
|
||||
{
|
||||
byte[] array = new byte[size];
|
||||
KeyBuilder.Rng.GetBytes(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060008EA RID: 2282 RVA: 0x00023078 File Offset: 0x00021278
|
||||
public static byte[] IV(int size)
|
||||
{
|
||||
byte[] array = new byte[size];
|
||||
KeyBuilder.Rng.GetBytes(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x040001DA RID: 474
|
||||
private static RandomNumberGenerator rng;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Mono.Xml;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A6 RID: 166
|
||||
internal class KeyPairPersistence
|
||||
{
|
||||
// Token: 0x06000913 RID: 2323 RVA: 0x00024114 File Offset: 0x00022314
|
||||
public KeyPairPersistence(CspParameters parameters)
|
||||
: this(parameters, null)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000914 RID: 2324 RVA: 0x00024120 File Offset: 0x00022320
|
||||
public KeyPairPersistence(CspParameters parameters, string keyPair)
|
||||
{
|
||||
if (parameters == null)
|
||||
{
|
||||
throw new ArgumentNullException("parameters");
|
||||
}
|
||||
this._params = this.Copy(parameters);
|
||||
this._keyvalue = keyPair;
|
||||
}
|
||||
|
||||
// Token: 0x170000FA RID: 250
|
||||
// (get) Token: 0x06000916 RID: 2326 RVA: 0x00024168 File Offset: 0x00022368
|
||||
public string Filename
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._filename == null)
|
||||
{
|
||||
this._filename = string.Format(CultureInfo.InvariantCulture, "[{0}][{1}][{2}].xml", new object[]
|
||||
{
|
||||
this._params.ProviderType,
|
||||
this.ContainerName,
|
||||
this._params.KeyNumber
|
||||
});
|
||||
if (this.UseMachineKeyStore)
|
||||
{
|
||||
this._filename = Path.Combine(KeyPairPersistence.MachinePath, this._filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._filename = Path.Combine(KeyPairPersistence.UserPath, this._filename);
|
||||
}
|
||||
}
|
||||
return this._filename;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000FB RID: 251
|
||||
// (get) Token: 0x06000917 RID: 2327 RVA: 0x0002420C File Offset: 0x0002240C
|
||||
// (set) Token: 0x06000918 RID: 2328 RVA: 0x00024214 File Offset: 0x00022414
|
||||
public string KeyValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._keyvalue;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.CanChange)
|
||||
{
|
||||
this._keyvalue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000FC RID: 252
|
||||
// (get) Token: 0x06000919 RID: 2329 RVA: 0x00024228 File Offset: 0x00022428
|
||||
public CspParameters Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Copy(this._params);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600091A RID: 2330 RVA: 0x00024238 File Offset: 0x00022438
|
||||
public bool Load()
|
||||
{
|
||||
if (Environment.SocketSecurityEnabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool flag = File.Exists(this.Filename);
|
||||
if (flag)
|
||||
{
|
||||
using (StreamReader streamReader = File.OpenText(this.Filename))
|
||||
{
|
||||
this.FromXml(streamReader.ReadToEnd());
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x0600091B RID: 2331 RVA: 0x000242AC File Offset: 0x000224AC
|
||||
public void Save()
|
||||
{
|
||||
if (Environment.SocketSecurityEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
using (FileStream fileStream = File.Open(this.Filename, FileMode.Create))
|
||||
{
|
||||
StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.UTF8);
|
||||
streamWriter.Write(this.ToXml());
|
||||
streamWriter.Close();
|
||||
}
|
||||
if (this.UseMachineKeyStore)
|
||||
{
|
||||
KeyPairPersistence.ProtectMachine(this.Filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
KeyPairPersistence.ProtectUser(this.Filename);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600091C RID: 2332 RVA: 0x00024348 File Offset: 0x00022548
|
||||
public void Remove()
|
||||
{
|
||||
if (Environment.SocketSecurityEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
File.Delete(this.Filename);
|
||||
}
|
||||
|
||||
// Token: 0x170000FD RID: 253
|
||||
// (get) Token: 0x0600091D RID: 2333 RVA: 0x00024360 File Offset: 0x00022560
|
||||
private static string UserPath
|
||||
{
|
||||
get
|
||||
{
|
||||
object obj = KeyPairPersistence.lockobj;
|
||||
lock (obj)
|
||||
{
|
||||
if (KeyPairPersistence._userPath == null || !KeyPairPersistence._userPathExists)
|
||||
{
|
||||
KeyPairPersistence._userPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".mono");
|
||||
KeyPairPersistence._userPath = Path.Combine(KeyPairPersistence._userPath, "keypairs");
|
||||
KeyPairPersistence._userPathExists = Directory.Exists(KeyPairPersistence._userPath);
|
||||
if (!KeyPairPersistence._userPathExists)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(KeyPairPersistence._userPath);
|
||||
KeyPairPersistence.ProtectUser(KeyPairPersistence._userPath);
|
||||
KeyPairPersistence._userPathExists = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string text = Locale.GetText("Could not create user key store '{0}'.");
|
||||
throw new CryptographicException(string.Format(text, KeyPairPersistence._userPath), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!KeyPairPersistence.IsUserProtected(KeyPairPersistence._userPath))
|
||||
{
|
||||
string text2 = Locale.GetText("Improperly protected user's key pairs in '{0}'.");
|
||||
throw new CryptographicException(string.Format(text2, KeyPairPersistence._userPath));
|
||||
}
|
||||
return KeyPairPersistence._userPath;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x170000FE RID: 254
|
||||
// (get) Token: 0x0600091E RID: 2334 RVA: 0x00024484 File Offset: 0x00022684
|
||||
private static string MachinePath
|
||||
{
|
||||
get
|
||||
{
|
||||
object obj = KeyPairPersistence.lockobj;
|
||||
lock (obj)
|
||||
{
|
||||
if (KeyPairPersistence._machinePath == null || !KeyPairPersistence._machinePathExists)
|
||||
{
|
||||
KeyPairPersistence._machinePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), ".mono");
|
||||
KeyPairPersistence._machinePath = Path.Combine(KeyPairPersistence._machinePath, "keypairs");
|
||||
KeyPairPersistence._machinePathExists = Directory.Exists(KeyPairPersistence._machinePath);
|
||||
if (!KeyPairPersistence._machinePathExists)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(KeyPairPersistence._machinePath);
|
||||
KeyPairPersistence.ProtectMachine(KeyPairPersistence._machinePath);
|
||||
KeyPairPersistence._machinePathExists = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string text = Locale.GetText("Could not create machine key store '{0}'.");
|
||||
throw new CryptographicException(string.Format(text, KeyPairPersistence._machinePath), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!KeyPairPersistence.IsMachineProtected(KeyPairPersistence._machinePath))
|
||||
{
|
||||
string text2 = Locale.GetText("Improperly protected machine's key pairs in '{0}'.");
|
||||
throw new CryptographicException(string.Format(text2, KeyPairPersistence._machinePath));
|
||||
}
|
||||
return KeyPairPersistence._machinePath;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600091F RID: 2335
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _CanSecure(string root);
|
||||
|
||||
// Token: 0x06000920 RID: 2336
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _ProtectUser(string path);
|
||||
|
||||
// Token: 0x06000921 RID: 2337
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _ProtectMachine(string path);
|
||||
|
||||
// Token: 0x06000922 RID: 2338
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _IsUserProtected(string path);
|
||||
|
||||
// Token: 0x06000923 RID: 2339
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern bool _IsMachineProtected(string path);
|
||||
|
||||
// Token: 0x06000924 RID: 2340 RVA: 0x000245A8 File Offset: 0x000227A8
|
||||
private static bool CanSecure(string path)
|
||||
{
|
||||
int platform = (int)Environment.OSVersion.Platform;
|
||||
return platform == 4 || platform == 128 || platform == 6 || KeyPairPersistence._CanSecure(Path.GetPathRoot(path));
|
||||
}
|
||||
|
||||
// Token: 0x06000925 RID: 2341 RVA: 0x000245E8 File Offset: 0x000227E8
|
||||
private static bool ProtectUser(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._ProtectUser(path);
|
||||
}
|
||||
|
||||
// Token: 0x06000926 RID: 2342 RVA: 0x00024600 File Offset: 0x00022800
|
||||
private static bool ProtectMachine(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._ProtectMachine(path);
|
||||
}
|
||||
|
||||
// Token: 0x06000927 RID: 2343 RVA: 0x00024618 File Offset: 0x00022818
|
||||
private static bool IsUserProtected(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._IsUserProtected(path);
|
||||
}
|
||||
|
||||
// Token: 0x06000928 RID: 2344 RVA: 0x00024630 File Offset: 0x00022830
|
||||
private static bool IsMachineProtected(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._IsMachineProtected(path);
|
||||
}
|
||||
|
||||
// Token: 0x170000FF RID: 255
|
||||
// (get) Token: 0x06000929 RID: 2345 RVA: 0x00024648 File Offset: 0x00022848
|
||||
private bool CanChange
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._keyvalue == null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000100 RID: 256
|
||||
// (get) Token: 0x0600092A RID: 2346 RVA: 0x00024654 File Offset: 0x00022854
|
||||
private bool UseDefaultKeyContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._params.Flags & CspProviderFlags.UseDefaultKeyContainer) == CspProviderFlags.UseDefaultKeyContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000101 RID: 257
|
||||
// (get) Token: 0x0600092B RID: 2347 RVA: 0x00024668 File Offset: 0x00022868
|
||||
private bool UseMachineKeyStore
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._params.Flags & CspProviderFlags.UseMachineKeyStore) == CspProviderFlags.UseMachineKeyStore;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000102 RID: 258
|
||||
// (get) Token: 0x0600092C RID: 2348 RVA: 0x0002467C File Offset: 0x0002287C
|
||||
private string ContainerName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._container == null)
|
||||
{
|
||||
if (this.UseDefaultKeyContainer)
|
||||
{
|
||||
this._container = "default";
|
||||
}
|
||||
else if (this._params.KeyContainerName == null || this._params.KeyContainerName.Length == 0)
|
||||
{
|
||||
this._container = Guid.NewGuid().ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(this._params.KeyContainerName);
|
||||
MD5 md = MD5.Create();
|
||||
byte[] array = md.ComputeHash(bytes);
|
||||
Guid guid = new Guid(array);
|
||||
this._container = guid.ToString();
|
||||
}
|
||||
}
|
||||
return this._container;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600092D RID: 2349 RVA: 0x0002472C File Offset: 0x0002292C
|
||||
private CspParameters Copy(CspParameters p)
|
||||
{
|
||||
return new CspParameters(p.ProviderType, p.ProviderName, p.KeyContainerName)
|
||||
{
|
||||
KeyNumber = p.KeyNumber,
|
||||
Flags = p.Flags
|
||||
};
|
||||
}
|
||||
|
||||
// Token: 0x0600092E RID: 2350 RVA: 0x0002476C File Offset: 0x0002296C
|
||||
private void FromXml(string xml)
|
||||
{
|
||||
SecurityParser securityParser = new SecurityParser();
|
||||
securityParser.LoadXml(xml);
|
||||
SecurityElement securityElement = securityParser.ToXml();
|
||||
if (securityElement.Tag == "KeyPair")
|
||||
{
|
||||
SecurityElement securityElement2 = securityElement.SearchForChildByTag("KeyValue");
|
||||
if (securityElement2.Children.Count > 0)
|
||||
{
|
||||
this._keyvalue = securityElement2.Children[0].ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600092F RID: 2351 RVA: 0x000247D8 File Offset: 0x000229D8
|
||||
private string ToXml()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.AppendFormat("<KeyPair>{0}\t<Properties>{0}\t\t<Provider ", Environment.NewLine);
|
||||
if (this._params.ProviderName != null && this._params.ProviderName.Length != 0)
|
||||
{
|
||||
stringBuilder.AppendFormat("Name=\"{0}\" ", this._params.ProviderName);
|
||||
}
|
||||
stringBuilder.AppendFormat("Type=\"{0}\" />{1}\t\t<Container ", this._params.ProviderType, Environment.NewLine);
|
||||
stringBuilder.AppendFormat("Name=\"{0}\" />{1}\t</Properties>{1}\t<KeyValue", this.ContainerName, Environment.NewLine);
|
||||
if (this._params.KeyNumber != -1)
|
||||
{
|
||||
stringBuilder.AppendFormat(" Id=\"{0}\" ", this._params.KeyNumber);
|
||||
}
|
||||
stringBuilder.AppendFormat(">{1}\t\t{0}{1}\t</KeyValue>{1}</KeyPair>{1}", this.KeyValue, Environment.NewLine);
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x040001F2 RID: 498
|
||||
private static bool _userPathExists = false;
|
||||
|
||||
// Token: 0x040001F3 RID: 499
|
||||
private static string _userPath;
|
||||
|
||||
// Token: 0x040001F4 RID: 500
|
||||
private static bool _machinePathExists = false;
|
||||
|
||||
// Token: 0x040001F5 RID: 501
|
||||
private static string _machinePath;
|
||||
|
||||
// Token: 0x040001F6 RID: 502
|
||||
private CspParameters _params;
|
||||
|
||||
// Token: 0x040001F7 RID: 503
|
||||
private string _keyvalue;
|
||||
|
||||
// Token: 0x040001F8 RID: 504
|
||||
private string _filename;
|
||||
|
||||
// Token: 0x040001F9 RID: 505
|
||||
private string _container;
|
||||
|
||||
// Token: 0x040001FA RID: 506
|
||||
private static object lockobj = new object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A7 RID: 167
|
||||
internal class MACAlgorithm
|
||||
{
|
||||
// Token: 0x06000930 RID: 2352 RVA: 0x000248BC File Offset: 0x00022ABC
|
||||
public MACAlgorithm(SymmetricAlgorithm algorithm)
|
||||
{
|
||||
this.algo = algorithm;
|
||||
this.algo.Mode = CipherMode.CBC;
|
||||
this.blockSize = this.algo.BlockSize >> 3;
|
||||
this.algo.IV = new byte[this.blockSize];
|
||||
this.block = new byte[this.blockSize];
|
||||
}
|
||||
|
||||
// Token: 0x06000931 RID: 2353 RVA: 0x0002491C File Offset: 0x00022B1C
|
||||
public void Initialize(byte[] key)
|
||||
{
|
||||
this.algo.Key = key;
|
||||
if (this.enc == null)
|
||||
{
|
||||
this.enc = this.algo.CreateEncryptor();
|
||||
}
|
||||
Array.Clear(this.block, 0, this.blockSize);
|
||||
this.blockCount = 0;
|
||||
}
|
||||
|
||||
// Token: 0x06000932 RID: 2354 RVA: 0x0002496C File Offset: 0x00022B6C
|
||||
public void Core(byte[] rgb, int ib, int cb)
|
||||
{
|
||||
int num = Math.Min(this.blockSize - this.blockCount, cb);
|
||||
Array.Copy(rgb, ib, this.block, this.blockCount, num);
|
||||
this.blockCount += num;
|
||||
if (this.blockCount == this.blockSize)
|
||||
{
|
||||
this.enc.TransformBlock(this.block, 0, this.blockSize, this.block, 0);
|
||||
int num2 = (cb - num) / this.blockSize;
|
||||
for (int i = 0; i < num2; i++)
|
||||
{
|
||||
this.enc.TransformBlock(rgb, num, this.blockSize, this.block, 0);
|
||||
num += this.blockSize;
|
||||
}
|
||||
this.blockCount = cb - num;
|
||||
if (this.blockCount > 0)
|
||||
{
|
||||
Array.Copy(rgb, num, this.block, 0, this.blockCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000933 RID: 2355 RVA: 0x00024A4C File Offset: 0x00022C4C
|
||||
public byte[] Final()
|
||||
{
|
||||
byte[] array;
|
||||
if (this.blockCount > 0 || (this.algo.Padding != PaddingMode.Zeros && this.algo.Padding != PaddingMode.None))
|
||||
{
|
||||
array = this.enc.TransformFinalBlock(this.block, 0, this.blockCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
array = (byte[])this.block.Clone();
|
||||
}
|
||||
if (!this.enc.CanReuseTransform)
|
||||
{
|
||||
this.enc.Dispose();
|
||||
this.enc = null;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x040001FB RID: 507
|
||||
private SymmetricAlgorithm algo;
|
||||
|
||||
// Token: 0x040001FC RID: 508
|
||||
private ICryptoTransform enc;
|
||||
|
||||
// Token: 0x040001FD RID: 509
|
||||
private byte[] block;
|
||||
|
||||
// Token: 0x040001FE RID: 510
|
||||
private int blockSize;
|
||||
|
||||
// Token: 0x040001FF RID: 511
|
||||
private int blockCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,394 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A8 RID: 168
|
||||
internal sealed class PKCS1
|
||||
{
|
||||
// Token: 0x06000934 RID: 2356 RVA: 0x00024ADC File Offset: 0x00022CDC
|
||||
private PKCS1()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000936 RID: 2358 RVA: 0x00024B50 File Offset: 0x00022D50
|
||||
private static bool Compare(byte[] array1, byte[] array2)
|
||||
{
|
||||
bool flag = array1.Length == array2.Length;
|
||||
if (flag)
|
||||
{
|
||||
for (int i = 0; i < array1.Length; i++)
|
||||
{
|
||||
if (array1[i] != array2[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06000937 RID: 2359 RVA: 0x00024B90 File Offset: 0x00022D90
|
||||
private static byte[] xor(byte[] array1, byte[] array2)
|
||||
{
|
||||
byte[] array3 = new byte[array1.Length];
|
||||
for (int i = 0; i < array3.Length; i++)
|
||||
{
|
||||
array3[i] = array1[i] ^ array2[i];
|
||||
}
|
||||
return array3;
|
||||
}
|
||||
|
||||
// Token: 0x06000938 RID: 2360 RVA: 0x00024BC8 File Offset: 0x00022DC8
|
||||
private static byte[] GetEmptyHash(HashAlgorithm hash)
|
||||
{
|
||||
if (hash is SHA1)
|
||||
{
|
||||
return PKCS1.emptySHA1;
|
||||
}
|
||||
if (hash is SHA256)
|
||||
{
|
||||
return PKCS1.emptySHA256;
|
||||
}
|
||||
if (hash is SHA384)
|
||||
{
|
||||
return PKCS1.emptySHA384;
|
||||
}
|
||||
if (hash is SHA512)
|
||||
{
|
||||
return PKCS1.emptySHA512;
|
||||
}
|
||||
return hash.ComputeHash(null);
|
||||
}
|
||||
|
||||
// Token: 0x06000939 RID: 2361 RVA: 0x00024C20 File Offset: 0x00022E20
|
||||
public static byte[] I2OSP(int x, int size)
|
||||
{
|
||||
byte[] bytes = BitConverterLE.GetBytes(x);
|
||||
Array.Reverse(bytes, 0, bytes.Length);
|
||||
return PKCS1.I2OSP(bytes, size);
|
||||
}
|
||||
|
||||
// Token: 0x0600093A RID: 2362 RVA: 0x00024C48 File Offset: 0x00022E48
|
||||
public static byte[] I2OSP(byte[] x, int size)
|
||||
{
|
||||
byte[] array = new byte[size];
|
||||
Buffer.BlockCopy(x, 0, array, array.Length - x.Length, x.Length);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x0600093B RID: 2363 RVA: 0x00024C70 File Offset: 0x00022E70
|
||||
public static byte[] OS2IP(byte[] x)
|
||||
{
|
||||
int num = 0;
|
||||
while (x[num++] == 0 && num < x.Length)
|
||||
{
|
||||
}
|
||||
num--;
|
||||
if (num > 0)
|
||||
{
|
||||
byte[] array = new byte[x.Length - num];
|
||||
Buffer.BlockCopy(x, num, array, 0, array.Length);
|
||||
return array;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
// Token: 0x0600093C RID: 2364 RVA: 0x00024CC0 File Offset: 0x00022EC0
|
||||
public static byte[] RSAEP(RSA rsa, byte[] m)
|
||||
{
|
||||
return rsa.EncryptValue(m);
|
||||
}
|
||||
|
||||
// Token: 0x0600093D RID: 2365 RVA: 0x00024CCC File Offset: 0x00022ECC
|
||||
public static byte[] RSADP(RSA rsa, byte[] c)
|
||||
{
|
||||
return rsa.DecryptValue(c);
|
||||
}
|
||||
|
||||
// Token: 0x0600093E RID: 2366 RVA: 0x00024CD8 File Offset: 0x00022ED8
|
||||
public static byte[] RSASP1(RSA rsa, byte[] m)
|
||||
{
|
||||
return rsa.DecryptValue(m);
|
||||
}
|
||||
|
||||
// Token: 0x0600093F RID: 2367 RVA: 0x00024CE4 File Offset: 0x00022EE4
|
||||
public static byte[] RSAVP1(RSA rsa, byte[] s)
|
||||
{
|
||||
return rsa.EncryptValue(s);
|
||||
}
|
||||
|
||||
// Token: 0x06000940 RID: 2368 RVA: 0x00024CF0 File Offset: 0x00022EF0
|
||||
public static byte[] Encrypt_OAEP(RSA rsa, HashAlgorithm hash, RandomNumberGenerator rng, byte[] M)
|
||||
{
|
||||
int num = rsa.KeySize / 8;
|
||||
int num2 = hash.HashSize / 8;
|
||||
if (M.Length > num - 2 * num2 - 2)
|
||||
{
|
||||
throw new CryptographicException("message too long");
|
||||
}
|
||||
byte[] emptyHash = PKCS1.GetEmptyHash(hash);
|
||||
int num3 = num - M.Length - 2 * num2 - 2;
|
||||
byte[] array = new byte[emptyHash.Length + num3 + 1 + M.Length];
|
||||
Buffer.BlockCopy(emptyHash, 0, array, 0, emptyHash.Length);
|
||||
array[emptyHash.Length + num3] = 1;
|
||||
Buffer.BlockCopy(M, 0, array, array.Length - M.Length, M.Length);
|
||||
byte[] array2 = new byte[num2];
|
||||
rng.GetBytes(array2);
|
||||
byte[] array3 = PKCS1.MGF1(hash, array2, num - num2 - 1);
|
||||
byte[] array4 = PKCS1.xor(array, array3);
|
||||
byte[] array5 = PKCS1.MGF1(hash, array4, num2);
|
||||
byte[] array6 = PKCS1.xor(array2, array5);
|
||||
byte[] array7 = new byte[array6.Length + array4.Length + 1];
|
||||
Buffer.BlockCopy(array6, 0, array7, 1, array6.Length);
|
||||
Buffer.BlockCopy(array4, 0, array7, array6.Length + 1, array4.Length);
|
||||
byte[] array8 = PKCS1.OS2IP(array7);
|
||||
byte[] array9 = PKCS1.RSAEP(rsa, array8);
|
||||
return PKCS1.I2OSP(array9, num);
|
||||
}
|
||||
|
||||
// Token: 0x06000941 RID: 2369 RVA: 0x00024E08 File Offset: 0x00023008
|
||||
public static byte[] Decrypt_OAEP(RSA rsa, HashAlgorithm hash, byte[] C)
|
||||
{
|
||||
int num = rsa.KeySize / 8;
|
||||
int num2 = hash.HashSize / 8;
|
||||
if (num < 2 * num2 + 2 || C.Length != num)
|
||||
{
|
||||
throw new CryptographicException("decryption error");
|
||||
}
|
||||
byte[] array = PKCS1.OS2IP(C);
|
||||
byte[] array2 = PKCS1.RSADP(rsa, array);
|
||||
byte[] array3 = PKCS1.I2OSP(array2, num);
|
||||
byte[] array4 = new byte[num2];
|
||||
Buffer.BlockCopy(array3, 1, array4, 0, array4.Length);
|
||||
byte[] array5 = new byte[num - num2 - 1];
|
||||
Buffer.BlockCopy(array3, array3.Length - array5.Length, array5, 0, array5.Length);
|
||||
byte[] array6 = PKCS1.MGF1(hash, array5, num2);
|
||||
byte[] array7 = PKCS1.xor(array4, array6);
|
||||
byte[] array8 = PKCS1.MGF1(hash, array7, num - num2 - 1);
|
||||
byte[] array9 = PKCS1.xor(array5, array8);
|
||||
byte[] emptyHash = PKCS1.GetEmptyHash(hash);
|
||||
byte[] array10 = new byte[emptyHash.Length];
|
||||
Buffer.BlockCopy(array9, 0, array10, 0, array10.Length);
|
||||
bool flag = PKCS1.Compare(emptyHash, array10);
|
||||
int num3 = emptyHash.Length;
|
||||
while (array9[num3] == 0)
|
||||
{
|
||||
num3++;
|
||||
}
|
||||
int num4 = array9.Length - num3 - 1;
|
||||
byte[] array11 = new byte[num4];
|
||||
Buffer.BlockCopy(array9, num3 + 1, array11, 0, num4);
|
||||
if (array3[0] != 0 || !flag || array9[num3] != 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return array11;
|
||||
}
|
||||
|
||||
// Token: 0x06000942 RID: 2370 RVA: 0x00024F54 File Offset: 0x00023154
|
||||
public static byte[] Encrypt_v15(RSA rsa, RandomNumberGenerator rng, byte[] M)
|
||||
{
|
||||
int num = rsa.KeySize / 8;
|
||||
if (M.Length > num - 11)
|
||||
{
|
||||
throw new CryptographicException("message too long");
|
||||
}
|
||||
int num2 = Math.Max(8, num - M.Length - 3);
|
||||
byte[] array = new byte[num2];
|
||||
rng.GetNonZeroBytes(array);
|
||||
byte[] array2 = new byte[num];
|
||||
array2[1] = 2;
|
||||
Buffer.BlockCopy(array, 0, array2, 2, num2);
|
||||
Buffer.BlockCopy(M, 0, array2, num - M.Length, M.Length);
|
||||
byte[] array3 = PKCS1.OS2IP(array2);
|
||||
byte[] array4 = PKCS1.RSAEP(rsa, array3);
|
||||
return PKCS1.I2OSP(array4, num);
|
||||
}
|
||||
|
||||
// Token: 0x06000943 RID: 2371 RVA: 0x00024FE0 File Offset: 0x000231E0
|
||||
public static byte[] Decrypt_v15(RSA rsa, byte[] C)
|
||||
{
|
||||
int num = rsa.KeySize >> 3;
|
||||
if (num < 11 || C.Length > num)
|
||||
{
|
||||
throw new CryptographicException("decryption error");
|
||||
}
|
||||
byte[] array = PKCS1.OS2IP(C);
|
||||
byte[] array2 = PKCS1.RSADP(rsa, array);
|
||||
byte[] array3 = PKCS1.I2OSP(array2, num);
|
||||
if (array3[0] != 0 || array3[1] != 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int num2 = 10;
|
||||
while (array3[num2] != 0 && num2 < array3.Length)
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
if (array3[num2] != 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
num2++;
|
||||
byte[] array4 = new byte[array3.Length - num2];
|
||||
Buffer.BlockCopy(array3, num2, array4, 0, array4.Length);
|
||||
return array4;
|
||||
}
|
||||
|
||||
// Token: 0x06000944 RID: 2372 RVA: 0x00025090 File Offset: 0x00023290
|
||||
public static byte[] Sign_v15(RSA rsa, HashAlgorithm hash, byte[] hashValue)
|
||||
{
|
||||
int num = rsa.KeySize >> 3;
|
||||
byte[] array = PKCS1.Encode_v15(hash, hashValue, num);
|
||||
byte[] array2 = PKCS1.OS2IP(array);
|
||||
byte[] array3 = PKCS1.RSASP1(rsa, array2);
|
||||
return PKCS1.I2OSP(array3, num);
|
||||
}
|
||||
|
||||
// Token: 0x06000945 RID: 2373 RVA: 0x000250CC File Offset: 0x000232CC
|
||||
public static bool Verify_v15(RSA rsa, HashAlgorithm hash, byte[] hashValue, byte[] signature)
|
||||
{
|
||||
return PKCS1.Verify_v15(rsa, hash, hashValue, signature, false);
|
||||
}
|
||||
|
||||
// Token: 0x06000946 RID: 2374 RVA: 0x000250D8 File Offset: 0x000232D8
|
||||
public static bool Verify_v15(RSA rsa, HashAlgorithm hash, byte[] hashValue, byte[] signature, bool tryNonStandardEncoding)
|
||||
{
|
||||
int num = rsa.KeySize >> 3;
|
||||
byte[] array = PKCS1.OS2IP(signature);
|
||||
byte[] array2 = PKCS1.RSAVP1(rsa, array);
|
||||
byte[] array3 = PKCS1.I2OSP(array2, num);
|
||||
byte[] array4 = PKCS1.Encode_v15(hash, hashValue, num);
|
||||
bool flag = PKCS1.Compare(array4, array3);
|
||||
if (flag || !tryNonStandardEncoding)
|
||||
{
|
||||
return flag;
|
||||
}
|
||||
if (array3[0] != 0 || array3[1] != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int i;
|
||||
for (i = 2; i < array3.Length - hashValue.Length - 1; i++)
|
||||
{
|
||||
if (array3[i] != 255)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (array3[i++] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
byte[] array5 = new byte[hashValue.Length];
|
||||
Buffer.BlockCopy(array3, i, array5, 0, array5.Length);
|
||||
return PKCS1.Compare(array5, hashValue);
|
||||
}
|
||||
|
||||
// Token: 0x06000947 RID: 2375 RVA: 0x0002519C File Offset: 0x0002339C
|
||||
public static byte[] Encode_v15(HashAlgorithm hash, byte[] hashValue, int emLength)
|
||||
{
|
||||
if (hashValue.Length != hash.HashSize >> 3)
|
||||
{
|
||||
throw new CryptographicException("bad hash length for " + hash.ToString());
|
||||
}
|
||||
string text = CryptoConfig.MapNameToOID(hash.ToString());
|
||||
byte[] array;
|
||||
if (text != null)
|
||||
{
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(new ASN1(CryptoConfig.EncodeOID(text)));
|
||||
asn.Add(new ASN1(5));
|
||||
ASN1 asn2 = new ASN1(4, hashValue);
|
||||
ASN1 asn3 = new ASN1(48);
|
||||
asn3.Add(asn);
|
||||
asn3.Add(asn2);
|
||||
array = asn3.GetBytes();
|
||||
}
|
||||
else
|
||||
{
|
||||
array = hashValue;
|
||||
}
|
||||
Buffer.BlockCopy(hashValue, 0, array, array.Length - hashValue.Length, hashValue.Length);
|
||||
int num = Math.Max(8, emLength - array.Length - 3);
|
||||
byte[] array2 = new byte[num + array.Length + 3];
|
||||
array2[1] = 1;
|
||||
for (int i = 2; i < num + 2; i++)
|
||||
{
|
||||
array2[i] = byte.MaxValue;
|
||||
}
|
||||
Buffer.BlockCopy(array, 0, array2, num + 3, array.Length);
|
||||
return array2;
|
||||
}
|
||||
|
||||
// Token: 0x06000948 RID: 2376 RVA: 0x000252A8 File Offset: 0x000234A8
|
||||
public static byte[] MGF1(HashAlgorithm hash, byte[] mgfSeed, int maskLen)
|
||||
{
|
||||
if (maskLen < 0)
|
||||
{
|
||||
throw new OverflowException();
|
||||
}
|
||||
int num = mgfSeed.Length;
|
||||
int num2 = hash.HashSize >> 3;
|
||||
int num3 = maskLen / num2;
|
||||
if (maskLen % num2 != 0)
|
||||
{
|
||||
num3++;
|
||||
}
|
||||
byte[] array = new byte[num3 * num2];
|
||||
byte[] array2 = new byte[num + 4];
|
||||
int num4 = 0;
|
||||
for (int i = 0; i < num3; i++)
|
||||
{
|
||||
byte[] array3 = PKCS1.I2OSP(i, 4);
|
||||
Buffer.BlockCopy(mgfSeed, 0, array2, 0, num);
|
||||
Buffer.BlockCopy(array3, 0, array2, num, 4);
|
||||
byte[] array4 = hash.ComputeHash(array2);
|
||||
Buffer.BlockCopy(array4, 0, array, num4, num2);
|
||||
num4 += num;
|
||||
}
|
||||
byte[] array5 = new byte[maskLen];
|
||||
Buffer.BlockCopy(array, 0, array5, 0, maskLen);
|
||||
return array5;
|
||||
}
|
||||
|
||||
// Token: 0x04000200 RID: 512
|
||||
private static byte[] emptySHA1 = new byte[]
|
||||
{
|
||||
218, 57, 163, 238, 94, 107, 75, 13, 50, 85,
|
||||
191, 239, 149, 96, 24, 144, 175, 216, 7, 9
|
||||
};
|
||||
|
||||
// Token: 0x04000201 RID: 513
|
||||
private static byte[] emptySHA256 = new byte[]
|
||||
{
|
||||
227, 176, 196, 66, 152, 252, 28, 20, 154, 251,
|
||||
244, 200, 153, 111, 185, 36, 39, 174, 65, 228,
|
||||
100, 155, 147, 76, 164, 149, 153, 27, 120, 82,
|
||||
184, 85
|
||||
};
|
||||
|
||||
// Token: 0x04000202 RID: 514
|
||||
private static byte[] emptySHA384 = new byte[]
|
||||
{
|
||||
56, 176, 96, 167, 81, 172, 150, 56, 76, 217,
|
||||
50, 126, 177, 177, 227, 106, 33, 253, 183, 17,
|
||||
20, 190, 7, 67, 76, 12, 199, 191, 99, 246,
|
||||
225, 218, 39, 78, 222, 191, 231, 111, 101, 251,
|
||||
213, 26, 210, 241, 72, 152, 185, 91
|
||||
};
|
||||
|
||||
// Token: 0x04000203 RID: 515
|
||||
private static byte[] emptySHA512 = new byte[]
|
||||
{
|
||||
207, 131, 225, 53, 126, 239, 184, 189, 241, 84,
|
||||
40, 80, 214, 109, 128, 7, 214, 32, 228, 5,
|
||||
11, 87, 21, 220, 131, 244, 169, 33, 211, 108,
|
||||
233, 206, 71, 208, 209, 60, 93, 133, 242, 176,
|
||||
byte.MaxValue, 131, 24, 210, 135, 126, 236, 47, 99, 185,
|
||||
49, 189, 71, 65, 122, 129, 165, 56, 50, 122,
|
||||
249, 39, 218, 62
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,515 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000A9 RID: 169
|
||||
internal sealed class PKCS8
|
||||
{
|
||||
// Token: 0x06000949 RID: 2377 RVA: 0x00025360 File Offset: 0x00023560
|
||||
private PKCS8()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x0600094A RID: 2378 RVA: 0x00025368 File Offset: 0x00023568
|
||||
public static PKCS8.KeyInfo GetType(byte[] data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
throw new ArgumentNullException("data");
|
||||
}
|
||||
PKCS8.KeyInfo keyInfo = PKCS8.KeyInfo.Unknown;
|
||||
try
|
||||
{
|
||||
ASN1 asn = new ASN1(data);
|
||||
if (asn.Tag == 48 && asn.Count > 0)
|
||||
{
|
||||
ASN1 asn2 = asn[0];
|
||||
byte tag = asn2.Tag;
|
||||
if (tag != 2)
|
||||
{
|
||||
if (tag == 48)
|
||||
{
|
||||
keyInfo = PKCS8.KeyInfo.EncryptedPrivateKey;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
keyInfo = PKCS8.KeyInfo.PrivateKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new CryptographicException("invalid ASN.1 data");
|
||||
}
|
||||
return keyInfo;
|
||||
}
|
||||
|
||||
// Token: 0x020000AA RID: 170
|
||||
public enum KeyInfo
|
||||
{
|
||||
// Token: 0x04000205 RID: 517
|
||||
PrivateKey,
|
||||
// Token: 0x04000206 RID: 518
|
||||
EncryptedPrivateKey,
|
||||
// Token: 0x04000207 RID: 519
|
||||
Unknown
|
||||
}
|
||||
|
||||
// Token: 0x020000AB RID: 171
|
||||
public class PrivateKeyInfo
|
||||
{
|
||||
// Token: 0x0600094B RID: 2379 RVA: 0x0002540C File Offset: 0x0002360C
|
||||
public PrivateKeyInfo()
|
||||
{
|
||||
this._version = 0;
|
||||
this._list = new ArrayList();
|
||||
}
|
||||
|
||||
// Token: 0x0600094C RID: 2380 RVA: 0x00025428 File Offset: 0x00023628
|
||||
public PrivateKeyInfo(byte[] data)
|
||||
: this()
|
||||
{
|
||||
this.Decode(data);
|
||||
}
|
||||
|
||||
// Token: 0x17000103 RID: 259
|
||||
// (get) Token: 0x0600094D RID: 2381 RVA: 0x00025438 File Offset: 0x00023638
|
||||
// (set) Token: 0x0600094E RID: 2382 RVA: 0x00025440 File Offset: 0x00023640
|
||||
public string Algorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._algorithm;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._algorithm = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000104 RID: 260
|
||||
// (get) Token: 0x0600094F RID: 2383 RVA: 0x0002544C File Offset: 0x0002364C
|
||||
public ArrayList Attributes
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._list;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000105 RID: 261
|
||||
// (get) Token: 0x06000950 RID: 2384 RVA: 0x00025454 File Offset: 0x00023654
|
||||
// (set) Token: 0x06000951 RID: 2385 RVA: 0x00025474 File Offset: 0x00023674
|
||||
public byte[] PrivateKey
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._key == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (byte[])this._key.Clone();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("PrivateKey");
|
||||
}
|
||||
this._key = (byte[])value.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000106 RID: 262
|
||||
// (get) Token: 0x06000952 RID: 2386 RVA: 0x000254A4 File Offset: 0x000236A4
|
||||
// (set) Token: 0x06000953 RID: 2387 RVA: 0x000254AC File Offset: 0x000236AC
|
||||
public int Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._version;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("negative version");
|
||||
}
|
||||
this._version = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000954 RID: 2388 RVA: 0x000254C8 File Offset: 0x000236C8
|
||||
private void Decode(byte[] data)
|
||||
{
|
||||
ASN1 asn = new ASN1(data);
|
||||
if (asn.Tag != 48)
|
||||
{
|
||||
throw new CryptographicException("invalid PrivateKeyInfo");
|
||||
}
|
||||
ASN1 asn2 = asn[0];
|
||||
if (asn2.Tag != 2)
|
||||
{
|
||||
throw new CryptographicException("invalid version");
|
||||
}
|
||||
this._version = (int)asn2.Value[0];
|
||||
ASN1 asn3 = asn[1];
|
||||
if (asn3.Tag != 48)
|
||||
{
|
||||
throw new CryptographicException("invalid algorithm");
|
||||
}
|
||||
ASN1 asn4 = asn3[0];
|
||||
if (asn4.Tag != 6)
|
||||
{
|
||||
throw new CryptographicException("missing algorithm OID");
|
||||
}
|
||||
this._algorithm = ASN1Convert.ToOid(asn4);
|
||||
ASN1 asn5 = asn[2];
|
||||
this._key = asn5.Value;
|
||||
if (asn.Count > 3)
|
||||
{
|
||||
ASN1 asn6 = asn[3];
|
||||
for (int i = 0; i < asn6.Count; i++)
|
||||
{
|
||||
this._list.Add(asn6[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000955 RID: 2389 RVA: 0x000255C8 File Offset: 0x000237C8
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(ASN1Convert.FromOid(this._algorithm));
|
||||
asn.Add(new ASN1(5));
|
||||
ASN1 asn2 = new ASN1(48);
|
||||
asn2.Add(new ASN1(2, new byte[] { (byte)this._version }));
|
||||
asn2.Add(asn);
|
||||
asn2.Add(new ASN1(4, this._key));
|
||||
if (this._list.Count > 0)
|
||||
{
|
||||
ASN1 asn3 = new ASN1(160);
|
||||
foreach (object obj in this._list)
|
||||
{
|
||||
ASN1 asn4 = (ASN1)obj;
|
||||
asn3.Add(asn4);
|
||||
}
|
||||
asn2.Add(asn3);
|
||||
}
|
||||
return asn2.GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x06000956 RID: 2390 RVA: 0x000256D0 File Offset: 0x000238D0
|
||||
private static byte[] RemoveLeadingZero(byte[] bigInt)
|
||||
{
|
||||
int num = 0;
|
||||
int num2 = bigInt.Length;
|
||||
if (bigInt[0] == 0)
|
||||
{
|
||||
num = 1;
|
||||
num2--;
|
||||
}
|
||||
byte[] array = new byte[num2];
|
||||
Buffer.BlockCopy(bigInt, num, array, 0, num2);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000957 RID: 2391 RVA: 0x00025704 File Offset: 0x00023904
|
||||
private static byte[] Normalize(byte[] bigInt, int length)
|
||||
{
|
||||
if (bigInt.Length == length)
|
||||
{
|
||||
return bigInt;
|
||||
}
|
||||
if (bigInt.Length > length)
|
||||
{
|
||||
return PKCS8.PrivateKeyInfo.RemoveLeadingZero(bigInt);
|
||||
}
|
||||
byte[] array = new byte[length];
|
||||
Buffer.BlockCopy(bigInt, 0, array, length - bigInt.Length, bigInt.Length);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000958 RID: 2392 RVA: 0x00025744 File Offset: 0x00023944
|
||||
public static RSA DecodeRSA(byte[] keypair)
|
||||
{
|
||||
ASN1 asn = new ASN1(keypair);
|
||||
if (asn.Tag != 48)
|
||||
{
|
||||
throw new CryptographicException("invalid private key format");
|
||||
}
|
||||
ASN1 asn2 = asn[0];
|
||||
if (asn2.Tag != 2)
|
||||
{
|
||||
throw new CryptographicException("missing version");
|
||||
}
|
||||
if (asn.Count < 9)
|
||||
{
|
||||
throw new CryptographicException("not enough key parameters");
|
||||
}
|
||||
RSAParameters rsaparameters = default(RSAParameters);
|
||||
rsaparameters.Modulus = PKCS8.PrivateKeyInfo.RemoveLeadingZero(asn[1].Value);
|
||||
int num = rsaparameters.Modulus.Length;
|
||||
int num2 = num >> 1;
|
||||
rsaparameters.D = PKCS8.PrivateKeyInfo.Normalize(asn[3].Value, num);
|
||||
rsaparameters.DP = PKCS8.PrivateKeyInfo.Normalize(asn[6].Value, num2);
|
||||
rsaparameters.DQ = PKCS8.PrivateKeyInfo.Normalize(asn[7].Value, num2);
|
||||
rsaparameters.Exponent = PKCS8.PrivateKeyInfo.RemoveLeadingZero(asn[2].Value);
|
||||
rsaparameters.InverseQ = PKCS8.PrivateKeyInfo.Normalize(asn[8].Value, num2);
|
||||
rsaparameters.P = PKCS8.PrivateKeyInfo.Normalize(asn[4].Value, num2);
|
||||
rsaparameters.Q = PKCS8.PrivateKeyInfo.Normalize(asn[5].Value, num2);
|
||||
RSA rsa = null;
|
||||
try
|
||||
{
|
||||
rsa = RSA.Create();
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
rsa = new RSACryptoServiceProvider(new CspParameters
|
||||
{
|
||||
Flags = CspProviderFlags.UseMachineKeyStore
|
||||
});
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
}
|
||||
return rsa;
|
||||
}
|
||||
|
||||
// Token: 0x06000959 RID: 2393 RVA: 0x000258E4 File Offset: 0x00023AE4
|
||||
public static byte[] Encode(RSA rsa)
|
||||
{
|
||||
RSAParameters rsaparameters = rsa.ExportParameters(true);
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(new ASN1(2, new byte[1]));
|
||||
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.Modulus));
|
||||
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.Exponent));
|
||||
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.D));
|
||||
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.P));
|
||||
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.Q));
|
||||
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.DP));
|
||||
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.DQ));
|
||||
asn.Add(ASN1Convert.FromUnsignedBigInteger(rsaparameters.InverseQ));
|
||||
return asn.GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x0600095A RID: 2394 RVA: 0x000259B4 File Offset: 0x00023BB4
|
||||
public static DSA DecodeDSA(byte[] privateKey, DSAParameters dsaParameters)
|
||||
{
|
||||
ASN1 asn = new ASN1(privateKey);
|
||||
if (asn.Tag != 2)
|
||||
{
|
||||
throw new CryptographicException("invalid private key format");
|
||||
}
|
||||
dsaParameters.X = PKCS8.PrivateKeyInfo.Normalize(asn.Value, 20);
|
||||
DSA dsa = DSA.Create();
|
||||
dsa.ImportParameters(dsaParameters);
|
||||
return dsa;
|
||||
}
|
||||
|
||||
// Token: 0x0600095B RID: 2395 RVA: 0x00025A04 File Offset: 0x00023C04
|
||||
public static byte[] Encode(DSA dsa)
|
||||
{
|
||||
return ASN1Convert.FromUnsignedBigInteger(dsa.ExportParameters(true).X).GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x0600095C RID: 2396 RVA: 0x00025A2C File Offset: 0x00023C2C
|
||||
public static byte[] Encode(AsymmetricAlgorithm aa)
|
||||
{
|
||||
if (aa is RSA)
|
||||
{
|
||||
return PKCS8.PrivateKeyInfo.Encode((RSA)aa);
|
||||
}
|
||||
if (aa is DSA)
|
||||
{
|
||||
return PKCS8.PrivateKeyInfo.Encode((DSA)aa);
|
||||
}
|
||||
throw new CryptographicException("Unknown asymmetric algorithm {0}", aa.ToString());
|
||||
}
|
||||
|
||||
// Token: 0x04000208 RID: 520
|
||||
private int _version;
|
||||
|
||||
// Token: 0x04000209 RID: 521
|
||||
private string _algorithm;
|
||||
|
||||
// Token: 0x0400020A RID: 522
|
||||
private byte[] _key;
|
||||
|
||||
// Token: 0x0400020B RID: 523
|
||||
private ArrayList _list;
|
||||
}
|
||||
|
||||
// Token: 0x020000AC RID: 172
|
||||
public class EncryptedPrivateKeyInfo
|
||||
{
|
||||
// Token: 0x0600095D RID: 2397 RVA: 0x00025A78 File Offset: 0x00023C78
|
||||
public EncryptedPrivateKeyInfo()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x0600095E RID: 2398 RVA: 0x00025A80 File Offset: 0x00023C80
|
||||
public EncryptedPrivateKeyInfo(byte[] data)
|
||||
: this()
|
||||
{
|
||||
this.Decode(data);
|
||||
}
|
||||
|
||||
// Token: 0x17000107 RID: 263
|
||||
// (get) Token: 0x0600095F RID: 2399 RVA: 0x00025A90 File Offset: 0x00023C90
|
||||
// (set) Token: 0x06000960 RID: 2400 RVA: 0x00025A98 File Offset: 0x00023C98
|
||||
public string Algorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._algorithm;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._algorithm = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000108 RID: 264
|
||||
// (get) Token: 0x06000961 RID: 2401 RVA: 0x00025AA4 File Offset: 0x00023CA4
|
||||
// (set) Token: 0x06000962 RID: 2402 RVA: 0x00025AC8 File Offset: 0x00023CC8
|
||||
public byte[] EncryptedData
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._data != null) ? ((byte[])this._data.Clone()) : null;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._data = ((value != null) ? ((byte[])value.Clone()) : null);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000109 RID: 265
|
||||
// (get) Token: 0x06000963 RID: 2403 RVA: 0x00025AE8 File Offset: 0x00023CE8
|
||||
// (set) Token: 0x06000964 RID: 2404 RVA: 0x00025B30 File Offset: 0x00023D30
|
||||
public byte[] Salt
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._salt == null)
|
||||
{
|
||||
RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create();
|
||||
this._salt = new byte[8];
|
||||
randomNumberGenerator.GetBytes(this._salt);
|
||||
}
|
||||
return (byte[])this._salt.Clone();
|
||||
}
|
||||
set
|
||||
{
|
||||
this._salt = (byte[])value.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700010A RID: 266
|
||||
// (get) Token: 0x06000965 RID: 2405 RVA: 0x00025B44 File Offset: 0x00023D44
|
||||
// (set) Token: 0x06000966 RID: 2406 RVA: 0x00025B4C File Offset: 0x00023D4C
|
||||
public int IterationCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._iterations;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("IterationCount", "Negative");
|
||||
}
|
||||
this._iterations = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000967 RID: 2407 RVA: 0x00025B6C File Offset: 0x00023D6C
|
||||
private void Decode(byte[] data)
|
||||
{
|
||||
ASN1 asn = new ASN1(data);
|
||||
if (asn.Tag != 48)
|
||||
{
|
||||
throw new CryptographicException("invalid EncryptedPrivateKeyInfo");
|
||||
}
|
||||
ASN1 asn2 = asn[0];
|
||||
if (asn2.Tag != 48)
|
||||
{
|
||||
throw new CryptographicException("invalid encryptionAlgorithm");
|
||||
}
|
||||
ASN1 asn3 = asn2[0];
|
||||
if (asn3.Tag != 6)
|
||||
{
|
||||
throw new CryptographicException("invalid algorithm");
|
||||
}
|
||||
this._algorithm = ASN1Convert.ToOid(asn3);
|
||||
if (asn2.Count > 1)
|
||||
{
|
||||
ASN1 asn4 = asn2[1];
|
||||
if (asn4.Tag != 48)
|
||||
{
|
||||
throw new CryptographicException("invalid parameters");
|
||||
}
|
||||
ASN1 asn5 = asn4[0];
|
||||
if (asn5.Tag != 4)
|
||||
{
|
||||
throw new CryptographicException("invalid salt");
|
||||
}
|
||||
this._salt = asn5.Value;
|
||||
ASN1 asn6 = asn4[1];
|
||||
if (asn6.Tag != 2)
|
||||
{
|
||||
throw new CryptographicException("invalid iterationCount");
|
||||
}
|
||||
this._iterations = ASN1Convert.ToInt32(asn6);
|
||||
}
|
||||
ASN1 asn7 = asn[1];
|
||||
if (asn7.Tag != 4)
|
||||
{
|
||||
throw new CryptographicException("invalid EncryptedData");
|
||||
}
|
||||
this._data = asn7.Value;
|
||||
}
|
||||
|
||||
// Token: 0x06000968 RID: 2408 RVA: 0x00025C9C File Offset: 0x00023E9C
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
if (this._algorithm == null)
|
||||
{
|
||||
throw new CryptographicException("No algorithm OID specified");
|
||||
}
|
||||
ASN1 asn = new ASN1(48);
|
||||
asn.Add(ASN1Convert.FromOid(this._algorithm));
|
||||
if (this._iterations > 0 || this._salt != null)
|
||||
{
|
||||
ASN1 asn2 = new ASN1(4, this._salt);
|
||||
ASN1 asn3 = ASN1Convert.FromInt32(this._iterations);
|
||||
ASN1 asn4 = new ASN1(48);
|
||||
asn4.Add(asn2);
|
||||
asn4.Add(asn3);
|
||||
asn.Add(asn4);
|
||||
}
|
||||
ASN1 asn5 = new ASN1(4, this._data);
|
||||
ASN1 asn6 = new ASN1(48);
|
||||
asn6.Add(asn);
|
||||
asn6.Add(asn5);
|
||||
return asn6.GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x0400020C RID: 524
|
||||
private string _algorithm;
|
||||
|
||||
// Token: 0x0400020D RID: 525
|
||||
private byte[] _salt;
|
||||
|
||||
// Token: 0x0400020E RID: 526
|
||||
private int _iterations;
|
||||
|
||||
// Token: 0x0400020F RID: 527
|
||||
private byte[] _data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,524 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Mono.Math;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000AD RID: 173
|
||||
internal class RSAManaged : RSA
|
||||
{
|
||||
// Token: 0x06000969 RID: 2409 RVA: 0x00025D5C File Offset: 0x00023F5C
|
||||
public RSAManaged()
|
||||
: this(1024)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x0600096A RID: 2410 RVA: 0x00025D6C File Offset: 0x00023F6C
|
||||
public RSAManaged(int keySize)
|
||||
{
|
||||
this.LegalKeySizesValue = new KeySizes[1];
|
||||
this.LegalKeySizesValue[0] = new KeySizes(384, 16384, 8);
|
||||
base.KeySize = keySize;
|
||||
}
|
||||
|
||||
// Token: 0x14000002 RID: 2
|
||||
// (add) Token: 0x0600096B RID: 2411 RVA: 0x00025DB4 File Offset: 0x00023FB4
|
||||
// (remove) Token: 0x0600096C RID: 2412 RVA: 0x00025DD0 File Offset: 0x00023FD0
|
||||
public event RSAManaged.KeyGeneratedEventHandler KeyGenerated;
|
||||
|
||||
// Token: 0x0600096D RID: 2413 RVA: 0x00025DEC File Offset: 0x00023FEC
|
||||
~RSAManaged()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
// Token: 0x0600096E RID: 2414 RVA: 0x00025E28 File Offset: 0x00024028
|
||||
private void GenerateKeyPair()
|
||||
{
|
||||
int num = this.KeySize + 1 >> 1;
|
||||
int num2 = this.KeySize - num;
|
||||
this.e = 17U;
|
||||
do
|
||||
{
|
||||
this.p = BigInteger.GeneratePseudoPrime(num);
|
||||
}
|
||||
while (this.p % 17U == 1U);
|
||||
for (;;)
|
||||
{
|
||||
do
|
||||
{
|
||||
this.q = BigInteger.GeneratePseudoPrime(num2);
|
||||
}
|
||||
while (this.q % 17U == 1U || !(this.p != this.q));
|
||||
this.n = this.p * this.q;
|
||||
if (this.n.BitCount() == this.KeySize)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (this.p < this.q)
|
||||
{
|
||||
this.p = this.q;
|
||||
}
|
||||
}
|
||||
BigInteger bigInteger = this.p - 1;
|
||||
BigInteger bigInteger2 = this.q - 1;
|
||||
BigInteger bigInteger3 = bigInteger * bigInteger2;
|
||||
this.d = this.e.ModInverse(bigInteger3);
|
||||
this.dp = this.d % bigInteger;
|
||||
this.dq = this.d % bigInteger2;
|
||||
this.qInv = this.q.ModInverse(this.p);
|
||||
this.keypairGenerated = true;
|
||||
this.isCRTpossible = true;
|
||||
if (this.KeyGenerated != null)
|
||||
{
|
||||
this.KeyGenerated(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700010B RID: 267
|
||||
// (get) Token: 0x0600096F RID: 2415 RVA: 0x00025FCC File Offset: 0x000241CC
|
||||
public override int KeySize
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.keypairGenerated)
|
||||
{
|
||||
int num = this.n.BitCount();
|
||||
if ((num & 7) != 0)
|
||||
{
|
||||
num += 8 - (num & 7);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
return base.KeySize;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700010C RID: 268
|
||||
// (get) Token: 0x06000970 RID: 2416 RVA: 0x00026008 File Offset: 0x00024208
|
||||
public override string KeyExchangeAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return "RSA-PKCS1-KeyEx";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700010D RID: 269
|
||||
// (get) Token: 0x06000971 RID: 2417 RVA: 0x00026010 File Offset: 0x00024210
|
||||
public bool PublicOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.keypairGenerated && (this.d == null || this.n == null);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700010E RID: 270
|
||||
// (get) Token: 0x06000972 RID: 2418 RVA: 0x0002604C File Offset: 0x0002424C
|
||||
public override string SignatureAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000973 RID: 2419 RVA: 0x00026054 File Offset: 0x00024254
|
||||
public override byte[] DecryptValue(byte[] rgb)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException("private key");
|
||||
}
|
||||
if (!this.keypairGenerated)
|
||||
{
|
||||
this.GenerateKeyPair();
|
||||
}
|
||||
BigInteger bigInteger = new BigInteger(rgb);
|
||||
BigInteger bigInteger2 = null;
|
||||
if (this.keyBlinding)
|
||||
{
|
||||
bigInteger2 = BigInteger.GenerateRandom(this.n.BitCount());
|
||||
bigInteger = bigInteger2.ModPow(this.e, this.n) * bigInteger % this.n;
|
||||
}
|
||||
BigInteger bigInteger6;
|
||||
if (this.isCRTpossible)
|
||||
{
|
||||
BigInteger bigInteger3 = bigInteger.ModPow(this.dp, this.p);
|
||||
BigInteger bigInteger4 = bigInteger.ModPow(this.dq, this.q);
|
||||
if (bigInteger4 > bigInteger3)
|
||||
{
|
||||
BigInteger bigInteger5 = this.p - (bigInteger4 - bigInteger3) * this.qInv % this.p;
|
||||
bigInteger6 = bigInteger4 + this.q * bigInteger5;
|
||||
}
|
||||
else
|
||||
{
|
||||
BigInteger bigInteger5 = (bigInteger3 - bigInteger4) * this.qInv % this.p;
|
||||
bigInteger6 = bigInteger4 + this.q * bigInteger5;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.PublicOnly)
|
||||
{
|
||||
throw new CryptographicException(Locale.GetText("Missing private key to decrypt value."));
|
||||
}
|
||||
bigInteger6 = bigInteger.ModPow(this.d, this.n);
|
||||
}
|
||||
if (this.keyBlinding)
|
||||
{
|
||||
bigInteger6 = bigInteger6 * bigInteger2.ModInverse(this.n) % this.n;
|
||||
bigInteger2.Clear();
|
||||
}
|
||||
byte[] paddedValue = this.GetPaddedValue(bigInteger6, this.KeySize >> 3);
|
||||
bigInteger.Clear();
|
||||
bigInteger6.Clear();
|
||||
return paddedValue;
|
||||
}
|
||||
|
||||
// Token: 0x06000974 RID: 2420 RVA: 0x00026210 File Offset: 0x00024410
|
||||
public override byte[] EncryptValue(byte[] rgb)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException("public key");
|
||||
}
|
||||
if (!this.keypairGenerated)
|
||||
{
|
||||
this.GenerateKeyPair();
|
||||
}
|
||||
BigInteger bigInteger = new BigInteger(rgb);
|
||||
BigInteger bigInteger2 = bigInteger.ModPow(this.e, this.n);
|
||||
byte[] paddedValue = this.GetPaddedValue(bigInteger2, this.KeySize >> 3);
|
||||
bigInteger.Clear();
|
||||
bigInteger2.Clear();
|
||||
return paddedValue;
|
||||
}
|
||||
|
||||
// Token: 0x06000975 RID: 2421 RVA: 0x0002627C File Offset: 0x0002447C
|
||||
public override RSAParameters ExportParameters(bool includePrivateParameters)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (!this.keypairGenerated)
|
||||
{
|
||||
this.GenerateKeyPair();
|
||||
}
|
||||
RSAParameters rsaparameters = default(RSAParameters);
|
||||
rsaparameters.Exponent = this.e.GetBytes();
|
||||
rsaparameters.Modulus = this.n.GetBytes();
|
||||
if (includePrivateParameters)
|
||||
{
|
||||
if (this.d == null)
|
||||
{
|
||||
throw new CryptographicException("Missing private key");
|
||||
}
|
||||
rsaparameters.D = this.d.GetBytes();
|
||||
if (rsaparameters.D.Length != rsaparameters.Modulus.Length)
|
||||
{
|
||||
byte[] array = new byte[rsaparameters.Modulus.Length];
|
||||
Buffer.BlockCopy(rsaparameters.D, 0, array, array.Length - rsaparameters.D.Length, rsaparameters.D.Length);
|
||||
rsaparameters.D = array;
|
||||
}
|
||||
if (this.p != null && this.q != null && this.dp != null && this.dq != null && this.qInv != null)
|
||||
{
|
||||
int num = this.KeySize >> 4;
|
||||
rsaparameters.P = this.GetPaddedValue(this.p, num);
|
||||
rsaparameters.Q = this.GetPaddedValue(this.q, num);
|
||||
rsaparameters.DP = this.GetPaddedValue(this.dp, num);
|
||||
rsaparameters.DQ = this.GetPaddedValue(this.dq, num);
|
||||
rsaparameters.InverseQ = this.GetPaddedValue(this.qInv, num);
|
||||
}
|
||||
}
|
||||
return rsaparameters;
|
||||
}
|
||||
|
||||
// Token: 0x06000976 RID: 2422 RVA: 0x0002642C File Offset: 0x0002462C
|
||||
public override void ImportParameters(RSAParameters parameters)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(Locale.GetText("Keypair was disposed"));
|
||||
}
|
||||
if (parameters.Exponent == null)
|
||||
{
|
||||
throw new CryptographicException(Locale.GetText("Missing Exponent"));
|
||||
}
|
||||
if (parameters.Modulus == null)
|
||||
{
|
||||
throw new CryptographicException(Locale.GetText("Missing Modulus"));
|
||||
}
|
||||
this.e = new BigInteger(parameters.Exponent);
|
||||
this.n = new BigInteger(parameters.Modulus);
|
||||
if (parameters.D != null)
|
||||
{
|
||||
this.d = new BigInteger(parameters.D);
|
||||
}
|
||||
if (parameters.DP != null)
|
||||
{
|
||||
this.dp = new BigInteger(parameters.DP);
|
||||
}
|
||||
if (parameters.DQ != null)
|
||||
{
|
||||
this.dq = new BigInteger(parameters.DQ);
|
||||
}
|
||||
if (parameters.InverseQ != null)
|
||||
{
|
||||
this.qInv = new BigInteger(parameters.InverseQ);
|
||||
}
|
||||
if (parameters.P != null)
|
||||
{
|
||||
this.p = new BigInteger(parameters.P);
|
||||
}
|
||||
if (parameters.Q != null)
|
||||
{
|
||||
this.q = new BigInteger(parameters.Q);
|
||||
}
|
||||
this.keypairGenerated = true;
|
||||
bool flag = this.p != null && this.q != null && this.dp != null;
|
||||
this.isCRTpossible = flag && this.dq != null && this.qInv != null;
|
||||
if (!flag)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool flag2 = this.n == this.p * this.q;
|
||||
if (flag2)
|
||||
{
|
||||
BigInteger bigInteger = this.p - 1;
|
||||
BigInteger bigInteger2 = this.q - 1;
|
||||
BigInteger bigInteger3 = bigInteger * bigInteger2;
|
||||
BigInteger bigInteger4 = this.e.ModInverse(bigInteger3);
|
||||
flag2 = this.d == bigInteger4;
|
||||
if (!flag2 && this.isCRTpossible)
|
||||
{
|
||||
flag2 = this.dp == bigInteger4 % bigInteger && this.dq == bigInteger4 % bigInteger2 && this.qInv == this.q.ModInverse(this.p);
|
||||
}
|
||||
}
|
||||
if (!flag2)
|
||||
{
|
||||
throw new CryptographicException(Locale.GetText("Private/public key mismatch"));
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000977 RID: 2423 RVA: 0x000266B4 File Offset: 0x000248B4
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.m_disposed)
|
||||
{
|
||||
if (this.d != null)
|
||||
{
|
||||
this.d.Clear();
|
||||
this.d = null;
|
||||
}
|
||||
if (this.p != null)
|
||||
{
|
||||
this.p.Clear();
|
||||
this.p = null;
|
||||
}
|
||||
if (this.q != null)
|
||||
{
|
||||
this.q.Clear();
|
||||
this.q = null;
|
||||
}
|
||||
if (this.dp != null)
|
||||
{
|
||||
this.dp.Clear();
|
||||
this.dp = null;
|
||||
}
|
||||
if (this.dq != null)
|
||||
{
|
||||
this.dq.Clear();
|
||||
this.dq = null;
|
||||
}
|
||||
if (this.qInv != null)
|
||||
{
|
||||
this.qInv.Clear();
|
||||
this.qInv = null;
|
||||
}
|
||||
if (disposing)
|
||||
{
|
||||
if (this.e != null)
|
||||
{
|
||||
this.e.Clear();
|
||||
this.e = null;
|
||||
}
|
||||
if (this.n != null)
|
||||
{
|
||||
this.n.Clear();
|
||||
this.n = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.m_disposed = true;
|
||||
}
|
||||
|
||||
// Token: 0x06000978 RID: 2424 RVA: 0x000267F4 File Offset: 0x000249F4
|
||||
public override string ToXmlString(bool includePrivateParameters)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
RSAParameters rsaparameters = this.ExportParameters(includePrivateParameters);
|
||||
try
|
||||
{
|
||||
stringBuilder.Append("<RSAKeyValue>");
|
||||
stringBuilder.Append("<Modulus>");
|
||||
stringBuilder.Append(Convert.ToBase64String(rsaparameters.Modulus));
|
||||
stringBuilder.Append("</Modulus>");
|
||||
stringBuilder.Append("<Exponent>");
|
||||
stringBuilder.Append(Convert.ToBase64String(rsaparameters.Exponent));
|
||||
stringBuilder.Append("</Exponent>");
|
||||
if (includePrivateParameters)
|
||||
{
|
||||
if (rsaparameters.P != null)
|
||||
{
|
||||
stringBuilder.Append("<P>");
|
||||
stringBuilder.Append(Convert.ToBase64String(rsaparameters.P));
|
||||
stringBuilder.Append("</P>");
|
||||
}
|
||||
if (rsaparameters.Q != null)
|
||||
{
|
||||
stringBuilder.Append("<Q>");
|
||||
stringBuilder.Append(Convert.ToBase64String(rsaparameters.Q));
|
||||
stringBuilder.Append("</Q>");
|
||||
}
|
||||
if (rsaparameters.DP != null)
|
||||
{
|
||||
stringBuilder.Append("<DP>");
|
||||
stringBuilder.Append(Convert.ToBase64String(rsaparameters.DP));
|
||||
stringBuilder.Append("</DP>");
|
||||
}
|
||||
if (rsaparameters.DQ != null)
|
||||
{
|
||||
stringBuilder.Append("<DQ>");
|
||||
stringBuilder.Append(Convert.ToBase64String(rsaparameters.DQ));
|
||||
stringBuilder.Append("</DQ>");
|
||||
}
|
||||
if (rsaparameters.InverseQ != null)
|
||||
{
|
||||
stringBuilder.Append("<InverseQ>");
|
||||
stringBuilder.Append(Convert.ToBase64String(rsaparameters.InverseQ));
|
||||
stringBuilder.Append("</InverseQ>");
|
||||
}
|
||||
stringBuilder.Append("<D>");
|
||||
stringBuilder.Append(Convert.ToBase64String(rsaparameters.D));
|
||||
stringBuilder.Append("</D>");
|
||||
}
|
||||
stringBuilder.Append("</RSAKeyValue>");
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (rsaparameters.P != null)
|
||||
{
|
||||
Array.Clear(rsaparameters.P, 0, rsaparameters.P.Length);
|
||||
}
|
||||
if (rsaparameters.Q != null)
|
||||
{
|
||||
Array.Clear(rsaparameters.Q, 0, rsaparameters.Q.Length);
|
||||
}
|
||||
if (rsaparameters.DP != null)
|
||||
{
|
||||
Array.Clear(rsaparameters.DP, 0, rsaparameters.DP.Length);
|
||||
}
|
||||
if (rsaparameters.DQ != null)
|
||||
{
|
||||
Array.Clear(rsaparameters.DQ, 0, rsaparameters.DQ.Length);
|
||||
}
|
||||
if (rsaparameters.InverseQ != null)
|
||||
{
|
||||
Array.Clear(rsaparameters.InverseQ, 0, rsaparameters.InverseQ.Length);
|
||||
}
|
||||
if (rsaparameters.D != null)
|
||||
{
|
||||
Array.Clear(rsaparameters.D, 0, rsaparameters.D.Length);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Token: 0x1700010F RID: 271
|
||||
// (get) Token: 0x06000979 RID: 2425 RVA: 0x00026ABC File Offset: 0x00024CBC
|
||||
// (set) Token: 0x0600097A RID: 2426 RVA: 0x00026AC4 File Offset: 0x00024CC4
|
||||
public bool UseKeyBlinding
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.keyBlinding;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.keyBlinding = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000110 RID: 272
|
||||
// (get) Token: 0x0600097B RID: 2427 RVA: 0x00026AD0 File Offset: 0x00024CD0
|
||||
public bool IsCrtPossible
|
||||
{
|
||||
get
|
||||
{
|
||||
return !this.keypairGenerated || this.isCRTpossible;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600097C RID: 2428 RVA: 0x00026AE8 File Offset: 0x00024CE8
|
||||
private byte[] GetPaddedValue(BigInteger value, int length)
|
||||
{
|
||||
byte[] bytes = value.GetBytes();
|
||||
if (bytes.Length >= length)
|
||||
{
|
||||
return bytes;
|
||||
}
|
||||
byte[] array = new byte[length];
|
||||
Buffer.BlockCopy(bytes, 0, array, length - bytes.Length, bytes.Length);
|
||||
Array.Clear(bytes, 0, bytes.Length);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x04000210 RID: 528
|
||||
private const int defaultKeySize = 1024;
|
||||
|
||||
// Token: 0x04000211 RID: 529
|
||||
private bool isCRTpossible;
|
||||
|
||||
// Token: 0x04000212 RID: 530
|
||||
private bool keyBlinding = true;
|
||||
|
||||
// Token: 0x04000213 RID: 531
|
||||
private bool keypairGenerated;
|
||||
|
||||
// Token: 0x04000214 RID: 532
|
||||
private bool m_disposed;
|
||||
|
||||
// Token: 0x04000215 RID: 533
|
||||
private BigInteger d;
|
||||
|
||||
// Token: 0x04000216 RID: 534
|
||||
private BigInteger p;
|
||||
|
||||
// Token: 0x04000217 RID: 535
|
||||
private BigInteger q;
|
||||
|
||||
// Token: 0x04000218 RID: 536
|
||||
private BigInteger dp;
|
||||
|
||||
// Token: 0x04000219 RID: 537
|
||||
private BigInteger dq;
|
||||
|
||||
// Token: 0x0400021A RID: 538
|
||||
private BigInteger qInv;
|
||||
|
||||
// Token: 0x0400021B RID: 539
|
||||
private BigInteger n;
|
||||
|
||||
// Token: 0x0400021C RID: 540
|
||||
private BigInteger e;
|
||||
|
||||
// Token: 0x020006C5 RID: 1733
|
||||
// (Invoke) Token: 0x0600419C RID: 16796
|
||||
public delegate void KeyGeneratedEventHandler(object sender, EventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,556 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x020000AE RID: 174
|
||||
internal abstract class SymmetricTransform : IDisposable, ICryptoTransform
|
||||
{
|
||||
// Token: 0x0600097D RID: 2429 RVA: 0x00026B2C File Offset: 0x00024D2C
|
||||
public SymmetricTransform(SymmetricAlgorithm symmAlgo, bool encryption, byte[] rgbIV)
|
||||
{
|
||||
this.algo = symmAlgo;
|
||||
this.encrypt = encryption;
|
||||
this.BlockSizeByte = this.algo.BlockSize >> 3;
|
||||
if (rgbIV == null)
|
||||
{
|
||||
rgbIV = KeyBuilder.IV(this.BlockSizeByte);
|
||||
}
|
||||
else
|
||||
{
|
||||
rgbIV = (byte[])rgbIV.Clone();
|
||||
}
|
||||
if (rgbIV.Length < this.BlockSizeByte)
|
||||
{
|
||||
string text = Locale.GetText("IV is too small ({0} bytes), it should be {1} bytes long.", new object[] { rgbIV.Length, this.BlockSizeByte });
|
||||
throw new CryptographicException(text);
|
||||
}
|
||||
this.temp = new byte[this.BlockSizeByte];
|
||||
Buffer.BlockCopy(rgbIV, 0, this.temp, 0, Math.Min(this.BlockSizeByte, rgbIV.Length));
|
||||
this.temp2 = new byte[this.BlockSizeByte];
|
||||
this.FeedBackByte = this.algo.FeedbackSize >> 3;
|
||||
if (this.FeedBackByte != 0)
|
||||
{
|
||||
this.FeedBackIter = this.BlockSizeByte / this.FeedBackByte;
|
||||
}
|
||||
this.workBuff = new byte[this.BlockSizeByte];
|
||||
this.workout = new byte[this.BlockSizeByte];
|
||||
}
|
||||
|
||||
// Token: 0x0600097E RID: 2430 RVA: 0x00026C58 File Offset: 0x00024E58
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Token: 0x0600097F RID: 2431 RVA: 0x00026C68 File Offset: 0x00024E68
|
||||
~SymmetricTransform()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
// Token: 0x06000980 RID: 2432 RVA: 0x00026CA4 File Offset: 0x00024EA4
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.m_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Array.Clear(this.temp, 0, this.BlockSizeByte);
|
||||
this.temp = null;
|
||||
Array.Clear(this.temp2, 0, this.BlockSizeByte);
|
||||
this.temp2 = null;
|
||||
}
|
||||
this.m_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000111 RID: 273
|
||||
// (get) Token: 0x06000981 RID: 2433 RVA: 0x00026CFC File Offset: 0x00024EFC
|
||||
public virtual bool CanTransformMultipleBlocks
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000112 RID: 274
|
||||
// (get) Token: 0x06000982 RID: 2434 RVA: 0x00026D00 File Offset: 0x00024F00
|
||||
public virtual bool CanReuseTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000113 RID: 275
|
||||
// (get) Token: 0x06000983 RID: 2435 RVA: 0x00026D04 File Offset: 0x00024F04
|
||||
public virtual int InputBlockSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.BlockSizeByte;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000114 RID: 276
|
||||
// (get) Token: 0x06000984 RID: 2436 RVA: 0x00026D0C File Offset: 0x00024F0C
|
||||
public virtual int OutputBlockSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.BlockSizeByte;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000985 RID: 2437 RVA: 0x00026D14 File Offset: 0x00024F14
|
||||
protected virtual void Transform(byte[] input, byte[] output)
|
||||
{
|
||||
switch (this.algo.Mode)
|
||||
{
|
||||
case CipherMode.CBC:
|
||||
this.CBC(input, output);
|
||||
break;
|
||||
case CipherMode.ECB:
|
||||
this.ECB(input, output);
|
||||
break;
|
||||
case CipherMode.OFB:
|
||||
this.OFB(input, output);
|
||||
break;
|
||||
case CipherMode.CFB:
|
||||
this.CFB(input, output);
|
||||
break;
|
||||
case CipherMode.CTS:
|
||||
this.CTS(input, output);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Unkown CipherMode" + this.algo.Mode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000986 RID: 2438
|
||||
protected abstract void ECB(byte[] input, byte[] output);
|
||||
|
||||
// Token: 0x06000987 RID: 2439 RVA: 0x00026DB4 File Offset: 0x00024FB4
|
||||
protected virtual void CBC(byte[] input, byte[] output)
|
||||
{
|
||||
if (this.encrypt)
|
||||
{
|
||||
for (int i = 0; i < this.BlockSizeByte; i++)
|
||||
{
|
||||
byte[] array = this.temp;
|
||||
int num = i;
|
||||
array[num] ^= input[i];
|
||||
}
|
||||
this.ECB(this.temp, output);
|
||||
Buffer.BlockCopy(output, 0, this.temp, 0, this.BlockSizeByte);
|
||||
}
|
||||
else
|
||||
{
|
||||
Buffer.BlockCopy(input, 0, this.temp2, 0, this.BlockSizeByte);
|
||||
this.ECB(input, output);
|
||||
for (int j = 0; j < this.BlockSizeByte; j++)
|
||||
{
|
||||
int num2 = j;
|
||||
output[num2] ^= this.temp[j];
|
||||
}
|
||||
Buffer.BlockCopy(this.temp2, 0, this.temp, 0, this.BlockSizeByte);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000988 RID: 2440 RVA: 0x00026E80 File Offset: 0x00025080
|
||||
protected virtual void CFB(byte[] input, byte[] output)
|
||||
{
|
||||
if (this.encrypt)
|
||||
{
|
||||
for (int i = 0; i < this.FeedBackIter; i++)
|
||||
{
|
||||
this.ECB(this.temp, this.temp2);
|
||||
for (int j = 0; j < this.FeedBackByte; j++)
|
||||
{
|
||||
output[j + i] = this.temp2[j] ^ input[j + i];
|
||||
}
|
||||
Buffer.BlockCopy(this.temp, this.FeedBackByte, this.temp, 0, this.BlockSizeByte - this.FeedBackByte);
|
||||
Buffer.BlockCopy(output, i, this.temp, this.BlockSizeByte - this.FeedBackByte, this.FeedBackByte);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int k = 0; k < this.FeedBackIter; k++)
|
||||
{
|
||||
this.encrypt = true;
|
||||
this.ECB(this.temp, this.temp2);
|
||||
this.encrypt = false;
|
||||
Buffer.BlockCopy(this.temp, this.FeedBackByte, this.temp, 0, this.BlockSizeByte - this.FeedBackByte);
|
||||
Buffer.BlockCopy(input, k, this.temp, this.BlockSizeByte - this.FeedBackByte, this.FeedBackByte);
|
||||
for (int l = 0; l < this.FeedBackByte; l++)
|
||||
{
|
||||
output[l + k] = this.temp2[l] ^ input[l + k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000989 RID: 2441 RVA: 0x00026FE0 File Offset: 0x000251E0
|
||||
protected virtual void OFB(byte[] input, byte[] output)
|
||||
{
|
||||
throw new CryptographicException("OFB isn't supported by the framework");
|
||||
}
|
||||
|
||||
// Token: 0x0600098A RID: 2442 RVA: 0x00026FEC File Offset: 0x000251EC
|
||||
protected virtual void CTS(byte[] input, byte[] output)
|
||||
{
|
||||
throw new CryptographicException("CTS isn't supported by the framework");
|
||||
}
|
||||
|
||||
// Token: 0x0600098B RID: 2443 RVA: 0x00026FF8 File Offset: 0x000251F8
|
||||
private void CheckInput(byte[] inputBuffer, int inputOffset, int inputCount)
|
||||
{
|
||||
if (inputBuffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("inputBuffer");
|
||||
}
|
||||
if (inputOffset < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("inputOffset", "< 0");
|
||||
}
|
||||
if (inputCount < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("inputCount", "< 0");
|
||||
}
|
||||
if (inputOffset > inputBuffer.Length - inputCount)
|
||||
{
|
||||
throw new ArgumentException("inputBuffer", Locale.GetText("Overflow"));
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600098C RID: 2444 RVA: 0x00027064 File Offset: 0x00025264
|
||||
public virtual int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException("Object is disposed");
|
||||
}
|
||||
this.CheckInput(inputBuffer, inputOffset, inputCount);
|
||||
if (outputBuffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("outputBuffer");
|
||||
}
|
||||
if (outputOffset < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("outputOffset", "< 0");
|
||||
}
|
||||
int num = outputBuffer.Length - inputCount - outputOffset;
|
||||
if (!this.encrypt && 0 > num && (this.algo.Padding == PaddingMode.None || this.algo.Padding == PaddingMode.Zeros))
|
||||
{
|
||||
throw new CryptographicException("outputBuffer", Locale.GetText("Overflow"));
|
||||
}
|
||||
if (this.KeepLastBlock)
|
||||
{
|
||||
if (0 > num + this.BlockSizeByte)
|
||||
{
|
||||
throw new CryptographicException("outputBuffer", Locale.GetText("Overflow"));
|
||||
}
|
||||
}
|
||||
else if (0 > num)
|
||||
{
|
||||
if (inputBuffer.Length - inputOffset - outputBuffer.Length != this.BlockSizeByte)
|
||||
{
|
||||
throw new CryptographicException("outputBuffer", Locale.GetText("Overflow"));
|
||||
}
|
||||
inputCount = outputBuffer.Length - outputOffset;
|
||||
}
|
||||
return this.InternalTransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
|
||||
}
|
||||
|
||||
// Token: 0x17000115 RID: 277
|
||||
// (get) Token: 0x0600098D RID: 2445 RVA: 0x0002718C File Offset: 0x0002538C
|
||||
private bool KeepLastBlock
|
||||
{
|
||||
get
|
||||
{
|
||||
return !this.encrypt && this.algo.Padding != PaddingMode.None && this.algo.Padding != PaddingMode.Zeros;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600098E RID: 2446 RVA: 0x000271CC File Offset: 0x000253CC
|
||||
private int InternalTransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
|
||||
{
|
||||
int num = inputOffset;
|
||||
int num2;
|
||||
if (inputCount != this.BlockSizeByte)
|
||||
{
|
||||
if (inputCount % this.BlockSizeByte != 0)
|
||||
{
|
||||
throw new CryptographicException("Invalid input block size.");
|
||||
}
|
||||
num2 = inputCount / this.BlockSizeByte;
|
||||
}
|
||||
else
|
||||
{
|
||||
num2 = 1;
|
||||
}
|
||||
if (this.KeepLastBlock)
|
||||
{
|
||||
num2--;
|
||||
}
|
||||
int num3 = 0;
|
||||
if (this.lastBlock)
|
||||
{
|
||||
this.Transform(this.workBuff, this.workout);
|
||||
Buffer.BlockCopy(this.workout, 0, outputBuffer, outputOffset, this.BlockSizeByte);
|
||||
outputOffset += this.BlockSizeByte;
|
||||
num3 += this.BlockSizeByte;
|
||||
this.lastBlock = false;
|
||||
}
|
||||
for (int i = 0; i < num2; i++)
|
||||
{
|
||||
Buffer.BlockCopy(inputBuffer, num, this.workBuff, 0, this.BlockSizeByte);
|
||||
this.Transform(this.workBuff, this.workout);
|
||||
Buffer.BlockCopy(this.workout, 0, outputBuffer, outputOffset, this.BlockSizeByte);
|
||||
num += this.BlockSizeByte;
|
||||
outputOffset += this.BlockSizeByte;
|
||||
num3 += this.BlockSizeByte;
|
||||
}
|
||||
if (this.KeepLastBlock)
|
||||
{
|
||||
Buffer.BlockCopy(inputBuffer, num, this.workBuff, 0, this.BlockSizeByte);
|
||||
this.lastBlock = true;
|
||||
}
|
||||
return num3;
|
||||
}
|
||||
|
||||
// Token: 0x0600098F RID: 2447 RVA: 0x00027300 File Offset: 0x00025500
|
||||
private void Random(byte[] buffer, int start, int length)
|
||||
{
|
||||
if (this._rng == null)
|
||||
{
|
||||
this._rng = RandomNumberGenerator.Create();
|
||||
}
|
||||
byte[] array = new byte[length];
|
||||
this._rng.GetBytes(array);
|
||||
Buffer.BlockCopy(array, 0, buffer, start, length);
|
||||
}
|
||||
|
||||
// Token: 0x06000990 RID: 2448 RVA: 0x00027340 File Offset: 0x00025540
|
||||
private void ThrowBadPaddingException(PaddingMode padding, int length, int position)
|
||||
{
|
||||
string text = string.Format(Locale.GetText("Bad {0} padding."), padding);
|
||||
if (length >= 0)
|
||||
{
|
||||
text += string.Format(Locale.GetText(" Invalid length {0}."), length);
|
||||
}
|
||||
if (position >= 0)
|
||||
{
|
||||
text += string.Format(Locale.GetText(" Error found at position {0}."), position);
|
||||
}
|
||||
throw new CryptographicException(text);
|
||||
}
|
||||
|
||||
// Token: 0x06000991 RID: 2449 RVA: 0x000273B0 File Offset: 0x000255B0
|
||||
private byte[] FinalEncrypt(byte[] inputBuffer, int inputOffset, int inputCount)
|
||||
{
|
||||
int num = inputCount / this.BlockSizeByte * this.BlockSizeByte;
|
||||
int num2 = inputCount - num;
|
||||
int i = num;
|
||||
switch (this.algo.Padding)
|
||||
{
|
||||
case PaddingMode.PKCS7:
|
||||
case PaddingMode.ANSIX923:
|
||||
case PaddingMode.ISO10126:
|
||||
i += this.BlockSizeByte;
|
||||
goto IL_A8;
|
||||
}
|
||||
if (inputCount == 0)
|
||||
{
|
||||
return new byte[0];
|
||||
}
|
||||
if (num2 != 0)
|
||||
{
|
||||
if (this.algo.Padding == PaddingMode.None)
|
||||
{
|
||||
throw new CryptographicException("invalid block length");
|
||||
}
|
||||
byte[] array = new byte[num + this.BlockSizeByte];
|
||||
Buffer.BlockCopy(inputBuffer, inputOffset, array, 0, inputCount);
|
||||
inputBuffer = array;
|
||||
inputOffset = 0;
|
||||
inputCount = array.Length;
|
||||
i = inputCount;
|
||||
}
|
||||
IL_A8:
|
||||
byte[] array2 = new byte[i];
|
||||
int num3 = 0;
|
||||
while (i > this.BlockSizeByte)
|
||||
{
|
||||
this.InternalTransformBlock(inputBuffer, inputOffset, this.BlockSizeByte, array2, num3);
|
||||
inputOffset += this.BlockSizeByte;
|
||||
num3 += this.BlockSizeByte;
|
||||
i -= this.BlockSizeByte;
|
||||
}
|
||||
byte b = (byte)(this.BlockSizeByte - num2);
|
||||
switch (this.algo.Padding)
|
||||
{
|
||||
case PaddingMode.PKCS7:
|
||||
{
|
||||
int num4 = array2.Length;
|
||||
while (--num4 >= array2.Length - (int)b)
|
||||
{
|
||||
array2[num4] = b;
|
||||
}
|
||||
Buffer.BlockCopy(inputBuffer, inputOffset, array2, num, num2);
|
||||
this.InternalTransformBlock(array2, num, this.BlockSizeByte, array2, num);
|
||||
return array2;
|
||||
}
|
||||
case PaddingMode.ANSIX923:
|
||||
array2[array2.Length - 1] = b;
|
||||
Buffer.BlockCopy(inputBuffer, inputOffset, array2, num, num2);
|
||||
this.InternalTransformBlock(array2, num, this.BlockSizeByte, array2, num);
|
||||
return array2;
|
||||
case PaddingMode.ISO10126:
|
||||
this.Random(array2, array2.Length - (int)b, (int)(b - 1));
|
||||
array2[array2.Length - 1] = b;
|
||||
Buffer.BlockCopy(inputBuffer, inputOffset, array2, num, num2);
|
||||
this.InternalTransformBlock(array2, num, this.BlockSizeByte, array2, num);
|
||||
return array2;
|
||||
}
|
||||
this.InternalTransformBlock(inputBuffer, inputOffset, this.BlockSizeByte, array2, num3);
|
||||
return array2;
|
||||
}
|
||||
|
||||
// Token: 0x06000992 RID: 2450 RVA: 0x000275BC File Offset: 0x000257BC
|
||||
private byte[] FinalDecrypt(byte[] inputBuffer, int inputOffset, int inputCount)
|
||||
{
|
||||
if (inputCount % this.BlockSizeByte > 0)
|
||||
{
|
||||
throw new CryptographicException("Invalid input block size.");
|
||||
}
|
||||
int num = inputCount;
|
||||
if (this.lastBlock)
|
||||
{
|
||||
num += this.BlockSizeByte;
|
||||
}
|
||||
byte[] array = new byte[num];
|
||||
int num2 = 0;
|
||||
while (inputCount > 0)
|
||||
{
|
||||
int num3 = this.InternalTransformBlock(inputBuffer, inputOffset, this.BlockSizeByte, array, num2);
|
||||
inputOffset += this.BlockSizeByte;
|
||||
num2 += num3;
|
||||
inputCount -= this.BlockSizeByte;
|
||||
}
|
||||
if (this.lastBlock)
|
||||
{
|
||||
this.Transform(this.workBuff, this.workout);
|
||||
Buffer.BlockCopy(this.workout, 0, array, num2, this.BlockSizeByte);
|
||||
num2 += this.BlockSizeByte;
|
||||
this.lastBlock = false;
|
||||
}
|
||||
byte b = ((num <= 0) ? 0 : array[num - 1]);
|
||||
switch (this.algo.Padding)
|
||||
{
|
||||
case PaddingMode.PKCS7:
|
||||
{
|
||||
if (b == 0 || (int)b > this.BlockSizeByte)
|
||||
{
|
||||
this.ThrowBadPaddingException(this.algo.Padding, (int)b, -1);
|
||||
}
|
||||
for (int i = (int)(b - 1); i > 0; i--)
|
||||
{
|
||||
if (array[num - 1 - i] != b)
|
||||
{
|
||||
this.ThrowBadPaddingException(this.algo.Padding, -1, i);
|
||||
}
|
||||
}
|
||||
num -= (int)b;
|
||||
break;
|
||||
}
|
||||
case PaddingMode.ANSIX923:
|
||||
{
|
||||
if (b == 0 || (int)b > this.BlockSizeByte)
|
||||
{
|
||||
this.ThrowBadPaddingException(this.algo.Padding, (int)b, -1);
|
||||
}
|
||||
for (int j = (int)(b - 1); j > 0; j--)
|
||||
{
|
||||
if (array[num - 1 - j] != 0)
|
||||
{
|
||||
this.ThrowBadPaddingException(this.algo.Padding, -1, j);
|
||||
}
|
||||
}
|
||||
num -= (int)b;
|
||||
break;
|
||||
}
|
||||
case PaddingMode.ISO10126:
|
||||
if (b == 0 || (int)b > this.BlockSizeByte)
|
||||
{
|
||||
this.ThrowBadPaddingException(this.algo.Padding, (int)b, -1);
|
||||
}
|
||||
num -= (int)b;
|
||||
break;
|
||||
}
|
||||
if (num > 0)
|
||||
{
|
||||
byte[] array2 = new byte[num];
|
||||
Buffer.BlockCopy(array, 0, array2, 0, num);
|
||||
Array.Clear(array, 0, array.Length);
|
||||
return array2;
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
// Token: 0x06000993 RID: 2451 RVA: 0x000277F8 File Offset: 0x000259F8
|
||||
public virtual byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
|
||||
{
|
||||
if (this.m_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException("Object is disposed");
|
||||
}
|
||||
this.CheckInput(inputBuffer, inputOffset, inputCount);
|
||||
if (this.encrypt)
|
||||
{
|
||||
return this.FinalEncrypt(inputBuffer, inputOffset, inputCount);
|
||||
}
|
||||
return this.FinalDecrypt(inputBuffer, inputOffset, inputCount);
|
||||
}
|
||||
|
||||
// Token: 0x0400021E RID: 542
|
||||
protected SymmetricAlgorithm algo;
|
||||
|
||||
// Token: 0x0400021F RID: 543
|
||||
protected bool encrypt;
|
||||
|
||||
// Token: 0x04000220 RID: 544
|
||||
private int BlockSizeByte;
|
||||
|
||||
// Token: 0x04000221 RID: 545
|
||||
private byte[] temp;
|
||||
|
||||
// Token: 0x04000222 RID: 546
|
||||
private byte[] temp2;
|
||||
|
||||
// Token: 0x04000223 RID: 547
|
||||
private byte[] workBuff;
|
||||
|
||||
// Token: 0x04000224 RID: 548
|
||||
private byte[] workout;
|
||||
|
||||
// Token: 0x04000225 RID: 549
|
||||
private int FeedBackByte;
|
||||
|
||||
// Token: 0x04000226 RID: 550
|
||||
private int FeedBackIter;
|
||||
|
||||
// Token: 0x04000227 RID: 551
|
||||
private bool m_disposed;
|
||||
|
||||
// Token: 0x04000228 RID: 552
|
||||
private bool lastBlock;
|
||||
|
||||
// Token: 0x04000229 RID: 553
|
||||
private RandomNumberGenerator _rng;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user