scripts
This commit is contained in:
@@ -0,0 +1,224 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000023 RID: 35
|
||||
public class ARC4Managed : RC4, IDisposable, ICryptoTransform
|
||||
{
|
||||
// Token: 0x06000178 RID: 376 RVA: 0x00009F34 File Offset: 0x00008134
|
||||
public ARC4Managed()
|
||||
{
|
||||
this.state = new byte[256];
|
||||
this.m_disposed = false;
|
||||
}
|
||||
|
||||
// Token: 0x06000179 RID: 377 RVA: 0x00009F54 File Offset: 0x00008154
|
||||
~ARC4Managed()
|
||||
{
|
||||
this.Dispose(true);
|
||||
}
|
||||
|
||||
// Token: 0x0600017A RID: 378 RVA: 0x00009F90 File Offset: 0x00008190
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.m_disposed)
|
||||
{
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
if (this.key != null)
|
||||
{
|
||||
Array.Clear(this.key, 0, this.key.Length);
|
||||
this.key = null;
|
||||
}
|
||||
Array.Clear(this.state, 0, this.state.Length);
|
||||
this.state = null;
|
||||
GC.SuppressFinalize(this);
|
||||
this.m_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000056 RID: 86
|
||||
// (get) Token: 0x0600017B RID: 379 RVA: 0x0000A004 File Offset: 0x00008204
|
||||
// (set) Token: 0x0600017C RID: 380 RVA: 0x0000A018 File Offset: 0x00008218
|
||||
public override byte[] Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return (byte[])this.key.Clone();
|
||||
}
|
||||
set
|
||||
{
|
||||
this.key = (byte[])value.Clone();
|
||||
this.KeySetup(this.key);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000057 RID: 87
|
||||
// (get) Token: 0x0600017D RID: 381 RVA: 0x0000A038 File Offset: 0x00008238
|
||||
public bool CanReuseTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600017E RID: 382 RVA: 0x0000A03C File Offset: 0x0000823C
|
||||
public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgvIV)
|
||||
{
|
||||
this.Key = rgbKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Token: 0x0600017F RID: 383 RVA: 0x0000A048 File Offset: 0x00008248
|
||||
public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgvIV)
|
||||
{
|
||||
this.Key = rgbKey;
|
||||
return this.CreateEncryptor();
|
||||
}
|
||||
|
||||
// Token: 0x06000180 RID: 384 RVA: 0x0000A058 File Offset: 0x00008258
|
||||
public override void GenerateIV()
|
||||
{
|
||||
this.IV = new byte[0];
|
||||
}
|
||||
|
||||
// Token: 0x06000181 RID: 385 RVA: 0x0000A068 File Offset: 0x00008268
|
||||
public override void GenerateKey()
|
||||
{
|
||||
this.Key = KeyBuilder.Key(this.KeySizeValue >> 3);
|
||||
}
|
||||
|
||||
// Token: 0x17000058 RID: 88
|
||||
// (get) Token: 0x06000182 RID: 386 RVA: 0x0000A080 File Offset: 0x00008280
|
||||
public bool CanTransformMultipleBlocks
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000059 RID: 89
|
||||
// (get) Token: 0x06000183 RID: 387 RVA: 0x0000A084 File Offset: 0x00008284
|
||||
public int InputBlockSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700005A RID: 90
|
||||
// (get) Token: 0x06000184 RID: 388 RVA: 0x0000A088 File Offset: 0x00008288
|
||||
public int OutputBlockSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000185 RID: 389 RVA: 0x0000A08C File Offset: 0x0000828C
|
||||
private void KeySetup(byte[] key)
|
||||
{
|
||||
byte b = 0;
|
||||
byte b2 = 0;
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
this.state[i] = (byte)i;
|
||||
}
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
for (int j = 0; j < 256; j++)
|
||||
{
|
||||
b2 = key[(int)b] + this.state[j] + b2;
|
||||
byte b3 = this.state[j];
|
||||
this.state[j] = this.state[(int)b2];
|
||||
this.state[(int)b2] = b3;
|
||||
b = (byte)((int)(b + 1) % key.Length);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000186 RID: 390 RVA: 0x0000A120 File Offset: 0x00008320
|
||||
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: 0x06000187 RID: 391 RVA: 0x0000A18C File Offset: 0x0000838C
|
||||
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
|
||||
{
|
||||
this.CheckInput(inputBuffer, inputOffset, inputCount);
|
||||
if (outputBuffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("outputBuffer");
|
||||
}
|
||||
if (outputOffset < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("outputOffset", "< 0");
|
||||
}
|
||||
if (outputOffset > outputBuffer.Length - inputCount)
|
||||
{
|
||||
throw new ArgumentException("outputBuffer", Locale.GetText("Overflow"));
|
||||
}
|
||||
return this.InternalTransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
|
||||
}
|
||||
|
||||
// Token: 0x06000188 RID: 392 RVA: 0x0000A1FC File Offset: 0x000083FC
|
||||
private int InternalTransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
|
||||
{
|
||||
for (int i = 0; i < inputCount; i++)
|
||||
{
|
||||
this.x += 1;
|
||||
this.y = this.state[(int)this.x] + this.y;
|
||||
byte b = this.state[(int)this.x];
|
||||
this.state[(int)this.x] = this.state[(int)this.y];
|
||||
this.state[(int)this.y] = b;
|
||||
byte b2 = this.state[(int)this.x] + this.state[(int)this.y];
|
||||
outputBuffer[outputOffset + i] = inputBuffer[inputOffset + i] ^ this.state[(int)b2];
|
||||
}
|
||||
return inputCount;
|
||||
}
|
||||
|
||||
// Token: 0x06000189 RID: 393 RVA: 0x0000A2B0 File Offset: 0x000084B0
|
||||
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
|
||||
{
|
||||
this.CheckInput(inputBuffer, inputOffset, inputCount);
|
||||
byte[] array = new byte[inputCount];
|
||||
this.InternalTransformBlock(inputBuffer, inputOffset, inputCount, array, 0);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x040000A9 RID: 169
|
||||
private byte[] key;
|
||||
|
||||
// Token: 0x040000AA RID: 170
|
||||
private byte[] state;
|
||||
|
||||
// Token: 0x040000AB RID: 171
|
||||
private byte x;
|
||||
|
||||
// Token: 0x040000AC RID: 172
|
||||
private byte y;
|
||||
|
||||
// Token: 0x040000AD RID: 173
|
||||
private bool m_disposed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000026 RID: 38
|
||||
public class BlockProcessor
|
||||
{
|
||||
// Token: 0x060001A9 RID: 425 RVA: 0x0000B510 File Offset: 0x00009710
|
||||
public BlockProcessor(ICryptoTransform transform)
|
||||
: this(transform, transform.InputBlockSize)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060001AA RID: 426 RVA: 0x0000B520 File Offset: 0x00009720
|
||||
public BlockProcessor(ICryptoTransform transform, int blockSize)
|
||||
{
|
||||
this.transform = transform;
|
||||
this.blockSize = blockSize;
|
||||
this.block = new byte[blockSize];
|
||||
}
|
||||
|
||||
// Token: 0x060001AB RID: 427 RVA: 0x0000B550 File Offset: 0x00009750
|
||||
~BlockProcessor()
|
||||
{
|
||||
Array.Clear(this.block, 0, this.blockSize);
|
||||
}
|
||||
|
||||
// Token: 0x060001AC RID: 428 RVA: 0x0000B598 File Offset: 0x00009798
|
||||
public void Initialize()
|
||||
{
|
||||
Array.Clear(this.block, 0, this.blockSize);
|
||||
this.blockCount = 0;
|
||||
}
|
||||
|
||||
// Token: 0x060001AD RID: 429 RVA: 0x0000B5B4 File Offset: 0x000097B4
|
||||
public void Core(byte[] rgb)
|
||||
{
|
||||
this.Core(rgb, 0, rgb.Length);
|
||||
}
|
||||
|
||||
// Token: 0x060001AE RID: 430 RVA: 0x0000B5C4 File Offset: 0x000097C4
|
||||
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: 0x060001AF RID: 431 RVA: 0x0000B6A8 File Offset: 0x000098A8
|
||||
public byte[] Final()
|
||||
{
|
||||
return this.transform.TransformFinalBlock(this.block, 0, this.blockCount);
|
||||
}
|
||||
|
||||
// Token: 0x040000AF RID: 175
|
||||
private ICryptoTransform transform;
|
||||
|
||||
// Token: 0x040000B0 RID: 176
|
||||
private byte[] block;
|
||||
|
||||
// Token: 0x040000B1 RID: 177
|
||||
private int blockSize;
|
||||
|
||||
// Token: 0x040000B2 RID: 178
|
||||
private int blockCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,692 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000024 RID: 36
|
||||
public sealed class CryptoConvert
|
||||
{
|
||||
// Token: 0x0600018A RID: 394 RVA: 0x0000A2DC File Offset: 0x000084DC
|
||||
private CryptoConvert()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x0600018B RID: 395 RVA: 0x0000A2E4 File Offset: 0x000084E4
|
||||
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: 0x0600018C RID: 396 RVA: 0x0000A304 File Offset: 0x00008504
|
||||
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: 0x0600018D RID: 397 RVA: 0x0000A324 File Offset: 0x00008524
|
||||
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: 0x0600018E RID: 398 RVA: 0x0000A36C File Offset: 0x0000856C
|
||||
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: 0x0600018F RID: 399 RVA: 0x0000A3B0 File Offset: 0x000085B0
|
||||
public static RSA FromCapiPrivateKeyBlob(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPrivateKeyBlob(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x06000190 RID: 400 RVA: 0x0000A3BC File Offset: 0x000085BC
|
||||
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 = null;
|
||||
try
|
||||
{
|
||||
rsa = RSA.Create();
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
}
|
||||
catch (CryptographicException ex2)
|
||||
{
|
||||
try
|
||||
{
|
||||
rsa = new RSACryptoServiceProvider(new CspParameters
|
||||
{
|
||||
Flags = CspProviderFlags.UseMachineKeyStore
|
||||
});
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw ex2;
|
||||
}
|
||||
}
|
||||
return rsa;
|
||||
}
|
||||
|
||||
// Token: 0x06000191 RID: 401 RVA: 0x0000A68C File Offset: 0x0000888C
|
||||
public static DSA FromCapiPrivateKeyBlobDSA(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPrivateKeyBlobDSA(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x06000192 RID: 402 RVA: 0x0000A698 File Offset: 0x00008898
|
||||
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 = null;
|
||||
try
|
||||
{
|
||||
dsa = DSA.Create();
|
||||
dsa.ImportParameters(dsaparameters);
|
||||
}
|
||||
catch (CryptographicException ex2)
|
||||
{
|
||||
try
|
||||
{
|
||||
dsa = new DSACryptoServiceProvider(new CspParameters
|
||||
{
|
||||
Flags = CspProviderFlags.UseMachineKeyStore
|
||||
});
|
||||
dsa.ImportParameters(dsaparameters);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw ex2;
|
||||
}
|
||||
}
|
||||
return dsa;
|
||||
}
|
||||
|
||||
// Token: 0x06000193 RID: 403 RVA: 0x0000A8DC File Offset: 0x00008ADC
|
||||
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: 0x06000194 RID: 404 RVA: 0x0000AAC4 File Offset: 0x00008CC4
|
||||
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: 0x06000195 RID: 405 RVA: 0x0000AC10 File Offset: 0x00008E10
|
||||
public static RSA FromCapiPublicKeyBlob(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPublicKeyBlob(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x06000196 RID: 406 RVA: 0x0000AC1C File Offset: 0x00008E1C
|
||||
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 = null;
|
||||
try
|
||||
{
|
||||
rsa = RSA.Create();
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
rsa = new RSACryptoServiceProvider(new CspParameters
|
||||
{
|
||||
Flags = CspProviderFlags.UseMachineKeyStore
|
||||
});
|
||||
rsa.ImportParameters(rsaparameters);
|
||||
}
|
||||
rsa2 = rsa;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CryptographicException("Invalid blob.", ex);
|
||||
}
|
||||
return rsa2;
|
||||
}
|
||||
|
||||
// Token: 0x06000197 RID: 407 RVA: 0x0000ADA8 File Offset: 0x00008FA8
|
||||
public static DSA FromCapiPublicKeyBlobDSA(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiPublicKeyBlobDSA(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x06000198 RID: 408 RVA: 0x0000ADB4 File Offset: 0x00008FB4
|
||||
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: 0x06000199 RID: 409 RVA: 0x0000AF90 File Offset: 0x00009190
|
||||
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: 0x0600019A RID: 410 RVA: 0x0000B068 File Offset: 0x00009268
|
||||
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: 0x0600019B RID: 411 RVA: 0x0000B1B0 File Offset: 0x000093B0
|
||||
public static RSA FromCapiKeyBlob(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiKeyBlob(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x0600019C RID: 412 RVA: 0x0000B1BC File Offset: 0x000093BC
|
||||
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: 0x0600019D RID: 413 RVA: 0x0000B244 File Offset: 0x00009444
|
||||
public static DSA FromCapiKeyBlobDSA(byte[] blob)
|
||||
{
|
||||
return CryptoConvert.FromCapiKeyBlobDSA(blob, 0);
|
||||
}
|
||||
|
||||
// Token: 0x0600019E RID: 414 RVA: 0x0000B250 File Offset: 0x00009450
|
||||
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: 0x0600019F RID: 415 RVA: 0x0000B2B4 File Offset: 0x000094B4
|
||||
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: 0x060001A0 RID: 416 RVA: 0x0000B304 File Offset: 0x00009504
|
||||
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: 0x060001A1 RID: 417 RVA: 0x0000B338 File Offset: 0x00009538
|
||||
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: 0x060001A2 RID: 418 RVA: 0x0000B36C File Offset: 0x0000956C
|
||||
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: 0x060001A3 RID: 419 RVA: 0x0000B3C4 File Offset: 0x000095C4
|
||||
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: 0x060001A4 RID: 420 RVA: 0x0000B424 File Offset: 0x00009624
|
||||
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,13 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000027 RID: 39
|
||||
public enum DHKeyGeneration
|
||||
{
|
||||
// Token: 0x040000B4 RID: 180
|
||||
Random,
|
||||
// Token: 0x040000B5 RID: 181
|
||||
Static
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000028 RID: 40
|
||||
[Serializable]
|
||||
public struct DHParameters
|
||||
{
|
||||
// Token: 0x040000B6 RID: 182
|
||||
public byte[] P;
|
||||
|
||||
// Token: 0x040000B7 RID: 183
|
||||
public byte[] G;
|
||||
|
||||
// Token: 0x040000B8 RID: 184
|
||||
[NonSerialized]
|
||||
public byte[] X;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Mono.Xml;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000029 RID: 41
|
||||
public abstract class DiffieHellman : AsymmetricAlgorithm
|
||||
{
|
||||
// Token: 0x060001B1 RID: 433 RVA: 0x0000B6CC File Offset: 0x000098CC
|
||||
public new static DiffieHellman Create()
|
||||
{
|
||||
return DiffieHellman.Create("Mono.Security.Cryptography.DiffieHellman");
|
||||
}
|
||||
|
||||
// Token: 0x060001B2 RID: 434 RVA: 0x0000B6D8 File Offset: 0x000098D8
|
||||
public new static DiffieHellman Create(string algName)
|
||||
{
|
||||
return (DiffieHellman)CryptoConfig.CreateFromName(algName);
|
||||
}
|
||||
|
||||
// Token: 0x060001B3 RID: 435
|
||||
public abstract byte[] CreateKeyExchange();
|
||||
|
||||
// Token: 0x060001B4 RID: 436
|
||||
public abstract byte[] DecryptKeyExchange(byte[] keyex);
|
||||
|
||||
// Token: 0x060001B5 RID: 437
|
||||
public abstract DHParameters ExportParameters(bool includePrivate);
|
||||
|
||||
// Token: 0x060001B6 RID: 438
|
||||
public abstract void ImportParameters(DHParameters parameters);
|
||||
|
||||
// Token: 0x060001B7 RID: 439 RVA: 0x0000B6E8 File Offset: 0x000098E8
|
||||
private byte[] GetNamedParam(SecurityElement se, string param)
|
||||
{
|
||||
SecurityElement securityElement = se.SearchForChildByTag(param);
|
||||
if (securityElement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Convert.FromBase64String(securityElement.Text);
|
||||
}
|
||||
|
||||
// Token: 0x060001B8 RID: 440 RVA: 0x0000B710 File Offset: 0x00009910
|
||||
public override void FromXmlString(string xmlString)
|
||||
{
|
||||
if (xmlString == null)
|
||||
{
|
||||
throw new ArgumentNullException("xmlString");
|
||||
}
|
||||
DHParameters dhparameters = default(DHParameters);
|
||||
try
|
||||
{
|
||||
SecurityParser securityParser = new SecurityParser();
|
||||
securityParser.LoadXml(xmlString);
|
||||
SecurityElement securityElement = securityParser.ToXml();
|
||||
if (securityElement.Tag != "DHKeyValue")
|
||||
{
|
||||
throw new CryptographicException();
|
||||
}
|
||||
dhparameters.P = this.GetNamedParam(securityElement, "P");
|
||||
dhparameters.G = this.GetNamedParam(securityElement, "G");
|
||||
dhparameters.X = this.GetNamedParam(securityElement, "X");
|
||||
this.ImportParameters(dhparameters);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dhparameters.P != null)
|
||||
{
|
||||
Array.Clear(dhparameters.P, 0, dhparameters.P.Length);
|
||||
}
|
||||
if (dhparameters.G != null)
|
||||
{
|
||||
Array.Clear(dhparameters.G, 0, dhparameters.G.Length);
|
||||
}
|
||||
if (dhparameters.X != null)
|
||||
{
|
||||
Array.Clear(dhparameters.X, 0, dhparameters.X.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060001B9 RID: 441 RVA: 0x0000B830 File Offset: 0x00009A30
|
||||
public override string ToXmlString(bool includePrivateParameters)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
DHParameters dhparameters = this.ExportParameters(includePrivateParameters);
|
||||
try
|
||||
{
|
||||
stringBuilder.Append("<DHKeyValue>");
|
||||
stringBuilder.Append("<P>");
|
||||
stringBuilder.Append(Convert.ToBase64String(dhparameters.P));
|
||||
stringBuilder.Append("</P>");
|
||||
stringBuilder.Append("<G>");
|
||||
stringBuilder.Append(Convert.ToBase64String(dhparameters.G));
|
||||
stringBuilder.Append("</G>");
|
||||
if (includePrivateParameters)
|
||||
{
|
||||
stringBuilder.Append("<X>");
|
||||
stringBuilder.Append(Convert.ToBase64String(dhparameters.X));
|
||||
stringBuilder.Append("</X>");
|
||||
}
|
||||
stringBuilder.Append("</DHKeyValue>");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Array.Clear(dhparameters.P, 0, dhparameters.P.Length);
|
||||
Array.Clear(dhparameters.G, 0, dhparameters.G.Length);
|
||||
if (dhparameters.X != null)
|
||||
{
|
||||
Array.Clear(dhparameters.X, 0, dhparameters.X.Length);
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using Mono.Math;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x0200002A RID: 42
|
||||
public sealed class DiffieHellmanManaged : DiffieHellman
|
||||
{
|
||||
// Token: 0x060001BA RID: 442 RVA: 0x0000B960 File Offset: 0x00009B60
|
||||
public DiffieHellmanManaged()
|
||||
: this(1024, 160, DHKeyGeneration.Static)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060001BB RID: 443 RVA: 0x0000B974 File Offset: 0x00009B74
|
||||
public DiffieHellmanManaged(int bitLength, int l, DHKeyGeneration method)
|
||||
{
|
||||
if (bitLength < 256 || l < 0)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
BigInteger bigInteger;
|
||||
BigInteger bigInteger2;
|
||||
this.GenerateKey(bitLength, method, out bigInteger, out bigInteger2);
|
||||
this.Initialize(bigInteger, bigInteger2, null, l, false);
|
||||
}
|
||||
|
||||
// Token: 0x060001BC RID: 444 RVA: 0x0000B9B8 File Offset: 0x00009BB8
|
||||
public DiffieHellmanManaged(byte[] p, byte[] g, byte[] x)
|
||||
{
|
||||
if (p == null || g == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
if (x == null)
|
||||
{
|
||||
this.Initialize(new BigInteger(p), new BigInteger(g), null, 0, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Initialize(new BigInteger(p), new BigInteger(g), new BigInteger(x), 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060001BD RID: 445 RVA: 0x0000BA18 File Offset: 0x00009C18
|
||||
public DiffieHellmanManaged(byte[] p, byte[] g, int l)
|
||||
{
|
||||
if (p == null || g == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
if (l < 0)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
this.Initialize(new BigInteger(p), new BigInteger(g), null, l, true);
|
||||
}
|
||||
|
||||
// Token: 0x060001BF RID: 447 RVA: 0x0000BAB8 File Offset: 0x00009CB8
|
||||
private void Initialize(BigInteger p, BigInteger g, BigInteger x, int secretLen, bool checkInput)
|
||||
{
|
||||
if (checkInput && (!p.IsProbablePrime() || g <= 0 || g >= p || (x != null && (x <= 0 || x > p - 2))))
|
||||
{
|
||||
throw new CryptographicException();
|
||||
}
|
||||
if (secretLen == 0)
|
||||
{
|
||||
secretLen = p.BitCount();
|
||||
}
|
||||
this.m_P = p;
|
||||
this.m_G = g;
|
||||
if (x == null)
|
||||
{
|
||||
BigInteger bigInteger = this.m_P - 1;
|
||||
this.m_X = BigInteger.GenerateRandom(secretLen);
|
||||
while (this.m_X >= bigInteger || this.m_X == 0U)
|
||||
{
|
||||
this.m_X = BigInteger.GenerateRandom(secretLen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_X = x;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060001C0 RID: 448 RVA: 0x0000BBB8 File Offset: 0x00009DB8
|
||||
public override byte[] CreateKeyExchange()
|
||||
{
|
||||
BigInteger bigInteger = this.m_G.ModPow(this.m_X, this.m_P);
|
||||
byte[] bytes = bigInteger.GetBytes();
|
||||
bigInteger.Clear();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// Token: 0x060001C1 RID: 449 RVA: 0x0000BBEC File Offset: 0x00009DEC
|
||||
public override byte[] DecryptKeyExchange(byte[] keyEx)
|
||||
{
|
||||
BigInteger bigInteger = new BigInteger(keyEx);
|
||||
BigInteger bigInteger2 = bigInteger.ModPow(this.m_X, this.m_P);
|
||||
byte[] bytes = bigInteger2.GetBytes();
|
||||
bigInteger2.Clear();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// Token: 0x1700005C RID: 92
|
||||
// (get) Token: 0x060001C2 RID: 450 RVA: 0x0000BC24 File Offset: 0x00009E24
|
||||
public override string KeyExchangeAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return "1.2.840.113549.1.3";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700005D RID: 93
|
||||
// (get) Token: 0x060001C3 RID: 451 RVA: 0x0000BC2C File Offset: 0x00009E2C
|
||||
public override string SignatureAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060001C4 RID: 452 RVA: 0x0000BC30 File Offset: 0x00009E30
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.m_Disposed)
|
||||
{
|
||||
this.m_P.Clear();
|
||||
this.m_G.Clear();
|
||||
this.m_X.Clear();
|
||||
}
|
||||
this.m_Disposed = true;
|
||||
}
|
||||
|
||||
// Token: 0x060001C5 RID: 453 RVA: 0x0000BC68 File Offset: 0x00009E68
|
||||
public override DHParameters ExportParameters(bool includePrivateParameters)
|
||||
{
|
||||
DHParameters dhparameters = default(DHParameters);
|
||||
dhparameters.P = this.m_P.GetBytes();
|
||||
dhparameters.G = this.m_G.GetBytes();
|
||||
if (includePrivateParameters)
|
||||
{
|
||||
dhparameters.X = this.m_X.GetBytes();
|
||||
}
|
||||
return dhparameters;
|
||||
}
|
||||
|
||||
// Token: 0x060001C6 RID: 454 RVA: 0x0000BCBC File Offset: 0x00009EBC
|
||||
public override void ImportParameters(DHParameters parameters)
|
||||
{
|
||||
if (parameters.P == null)
|
||||
{
|
||||
throw new CryptographicException("Missing P value.");
|
||||
}
|
||||
if (parameters.G == null)
|
||||
{
|
||||
throw new CryptographicException("Missing G value.");
|
||||
}
|
||||
BigInteger bigInteger = new BigInteger(parameters.P);
|
||||
BigInteger bigInteger2 = new BigInteger(parameters.G);
|
||||
BigInteger bigInteger3 = null;
|
||||
if (parameters.X != null)
|
||||
{
|
||||
bigInteger3 = new BigInteger(parameters.X);
|
||||
}
|
||||
this.Initialize(bigInteger, bigInteger2, bigInteger3, 0, true);
|
||||
}
|
||||
|
||||
// Token: 0x060001C7 RID: 455 RVA: 0x0000BD38 File Offset: 0x00009F38
|
||||
~DiffieHellmanManaged()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
// Token: 0x060001C8 RID: 456 RVA: 0x0000BD74 File Offset: 0x00009F74
|
||||
private void GenerateKey(int bitlen, DHKeyGeneration keygen, out BigInteger p, out BigInteger g)
|
||||
{
|
||||
if (keygen == DHKeyGeneration.Static)
|
||||
{
|
||||
if (bitlen == 768)
|
||||
{
|
||||
p = new BigInteger(DiffieHellmanManaged.m_OAKLEY768);
|
||||
}
|
||||
else if (bitlen == 1024)
|
||||
{
|
||||
p = new BigInteger(DiffieHellmanManaged.m_OAKLEY1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bitlen != 1536)
|
||||
{
|
||||
throw new ArgumentException("Invalid bit size.");
|
||||
}
|
||||
p = new BigInteger(DiffieHellmanManaged.m_OAKLEY1536);
|
||||
}
|
||||
g = new BigInteger(22U);
|
||||
}
|
||||
else
|
||||
{
|
||||
p = BigInteger.GeneratePseudoPrime(bitlen);
|
||||
g = new BigInteger(3U);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x040000B9 RID: 185
|
||||
private BigInteger m_P;
|
||||
|
||||
// Token: 0x040000BA RID: 186
|
||||
private BigInteger m_G;
|
||||
|
||||
// Token: 0x040000BB RID: 187
|
||||
private BigInteger m_X;
|
||||
|
||||
// Token: 0x040000BC RID: 188
|
||||
private bool m_Disposed;
|
||||
|
||||
// Token: 0x040000BD RID: 189
|
||||
private static byte[] m_OAKLEY768 = new byte[]
|
||||
{
|
||||
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, 201, 15,
|
||||
218, 162, 33, 104, 194, 52, 196, 198, 98, 139,
|
||||
128, 220, 28, 209, 41, 2, 78, 8, 138, 103,
|
||||
204, 116, 2, 11, 190, 166, 59, 19, 155, 34,
|
||||
81, 74, 8, 121, 142, 52, 4, 221, 239, 149,
|
||||
25, 179, 205, 58, 67, 27, 48, 43, 10, 109,
|
||||
242, 95, 20, 55, 79, 225, 53, 109, 109, 81,
|
||||
194, 69, 228, 133, 181, 118, 98, 94, 126, 198,
|
||||
244, 76, 66, 233, 166, 58, 54, 32, byte.MaxValue, byte.MaxValue,
|
||||
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue
|
||||
};
|
||||
|
||||
// Token: 0x040000BE RID: 190
|
||||
private static byte[] m_OAKLEY1024 = new byte[]
|
||||
{
|
||||
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, 201, 15,
|
||||
218, 162, 33, 104, 194, 52, 196, 198, 98, 139,
|
||||
128, 220, 28, 209, 41, 2, 78, 8, 138, 103,
|
||||
204, 116, 2, 11, 190, 166, 59, 19, 155, 34,
|
||||
81, 74, 8, 121, 142, 52, 4, 221, 239, 149,
|
||||
25, 179, 205, 58, 67, 27, 48, 43, 10, 109,
|
||||
242, 95, 20, 55, 79, 225, 53, 109, 109, 81,
|
||||
194, 69, 228, 133, 181, 118, 98, 94, 126, 198,
|
||||
244, 76, 66, 233, 166, 55, 237, 107, 11, byte.MaxValue,
|
||||
92, 182, 244, 6, 183, 237, 238, 56, 107, 251,
|
||||
90, 137, 159, 165, 174, 159, 36, 17, 124, 75,
|
||||
31, 230, 73, 40, 102, 81, 236, 230, 83, 129,
|
||||
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue
|
||||
};
|
||||
|
||||
// Token: 0x040000BF RID: 191
|
||||
private static byte[] m_OAKLEY1536 = new byte[]
|
||||
{
|
||||
byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, 201, 15,
|
||||
218, 162, 33, 104, 194, 52, 196, 198, 98, 139,
|
||||
128, 220, 28, 209, 41, 2, 78, 8, 138, 103,
|
||||
204, 116, 2, 11, 190, 166, 59, 19, 155, 34,
|
||||
81, 74, 8, 121, 142, 52, 4, 221, 239, 149,
|
||||
25, 179, 205, 58, 67, 27, 48, 43, 10, 109,
|
||||
242, 95, 20, 55, 79, 225, 53, 109, 109, 81,
|
||||
194, 69, 228, 133, 181, 118, 98, 94, 126, 198,
|
||||
244, 76, 66, 233, 166, 55, 237, 107, 11, byte.MaxValue,
|
||||
92, 182, 244, 6, 183, 237, 238, 56, 107, 251,
|
||||
90, 137, 159, 165, 174, 159, 36, 17, 124, 75,
|
||||
31, 230, 73, 40, 102, 81, 236, 228, 91, 61,
|
||||
194, 0, 124, 184, 161, 99, 191, 5, 152, 218,
|
||||
72, 54, 28, 85, 211, 154, 105, 22, 63, 168,
|
||||
253, 36, 207, 95, 131, 101, 93, 35, 220, 163,
|
||||
173, 150, 28, 98, 243, 86, 32, 133, 82, 187,
|
||||
158, 213, 41, 7, 112, 150, 150, 109, 103, 12,
|
||||
53, 78, 74, 188, 152, 4, 241, 116, 108, 8,
|
||||
202, 35, 115, 39, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue,
|
||||
byte.MaxValue, byte.MaxValue
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000074 RID: 116
|
||||
internal class HMAC : KeyedHashAlgorithm
|
||||
{
|
||||
// Token: 0x06000429 RID: 1065 RVA: 0x0001AE98 File Offset: 0x00019098
|
||||
public HMAC()
|
||||
{
|
||||
this.hash = MD5.Create();
|
||||
this.HashSizeValue = this.hash.HashSize;
|
||||
byte[] array = new byte[64];
|
||||
RNGCryptoServiceProvider rngcryptoServiceProvider = new RNGCryptoServiceProvider();
|
||||
rngcryptoServiceProvider.GetNonZeroBytes(array);
|
||||
this.KeyValue = (byte[])array.Clone();
|
||||
this.Initialize();
|
||||
}
|
||||
|
||||
// Token: 0x0600042A RID: 1066 RVA: 0x0001AEF4 File Offset: 0x000190F4
|
||||
public HMAC(string hashName, byte[] rgbKey)
|
||||
{
|
||||
if (hashName == null || hashName.Length == 0)
|
||||
{
|
||||
hashName = "MD5";
|
||||
}
|
||||
this.hash = HashAlgorithm.Create(hashName);
|
||||
this.HashSizeValue = this.hash.HashSize;
|
||||
if (rgbKey.Length > 64)
|
||||
{
|
||||
this.KeyValue = this.hash.ComputeHash(rgbKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.KeyValue = (byte[])rgbKey.Clone();
|
||||
}
|
||||
this.Initialize();
|
||||
}
|
||||
|
||||
// Token: 0x170000F4 RID: 244
|
||||
// (get) Token: 0x0600042B RID: 1067 RVA: 0x0001AF74 File Offset: 0x00019174
|
||||
// (set) Token: 0x0600042C RID: 1068 RVA: 0x0001AF88 File Offset: 0x00019188
|
||||
public override byte[] Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return (byte[])this.KeyValue.Clone();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.hashing)
|
||||
{
|
||||
throw new Exception("Cannot change key during hash operation.");
|
||||
}
|
||||
if (value.Length > 64)
|
||||
{
|
||||
this.KeyValue = this.hash.ComputeHash(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.KeyValue = (byte[])value.Clone();
|
||||
}
|
||||
this.initializePad();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600042D RID: 1069 RVA: 0x0001AFE4 File Offset: 0x000191E4
|
||||
public override void Initialize()
|
||||
{
|
||||
this.hash.Initialize();
|
||||
this.initializePad();
|
||||
this.hashing = false;
|
||||
}
|
||||
|
||||
// Token: 0x0600042E RID: 1070 RVA: 0x0001B000 File Offset: 0x00019200
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
if (!this.hashing)
|
||||
{
|
||||
this.hash.TransformBlock(this.innerPad, 0, this.innerPad.Length, this.innerPad, 0);
|
||||
this.hashing = true;
|
||||
}
|
||||
this.hash.TransformFinalBlock(new byte[0], 0, 0);
|
||||
byte[] array = this.hash.Hash;
|
||||
this.hash.Initialize();
|
||||
this.hash.TransformBlock(this.outerPad, 0, this.outerPad.Length, this.outerPad, 0);
|
||||
this.hash.TransformFinalBlock(array, 0, array.Length);
|
||||
this.Initialize();
|
||||
return this.hash.Hash;
|
||||
}
|
||||
|
||||
// Token: 0x0600042F RID: 1071 RVA: 0x0001B0B0 File Offset: 0x000192B0
|
||||
protected override void HashCore(byte[] array, int ibStart, int cbSize)
|
||||
{
|
||||
if (!this.hashing)
|
||||
{
|
||||
this.hash.TransformBlock(this.innerPad, 0, this.innerPad.Length, this.innerPad, 0);
|
||||
this.hashing = true;
|
||||
}
|
||||
this.hash.TransformBlock(array, ibStart, cbSize, array, ibStart);
|
||||
}
|
||||
|
||||
// Token: 0x06000430 RID: 1072 RVA: 0x0001B104 File Offset: 0x00019304
|
||||
private void initializePad()
|
||||
{
|
||||
this.innerPad = new byte[64];
|
||||
this.outerPad = new byte[64];
|
||||
for (int i = 0; i < this.KeyValue.Length; i++)
|
||||
{
|
||||
this.innerPad[i] = this.KeyValue[i] ^ 54;
|
||||
this.outerPad[i] = this.KeyValue[i] ^ 92;
|
||||
}
|
||||
for (int j = this.KeyValue.Length; j < 64; j++)
|
||||
{
|
||||
this.innerPad[j] = 54;
|
||||
this.outerPad[j] = 92;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x040001F1 RID: 497
|
||||
private HashAlgorithm hash;
|
||||
|
||||
// Token: 0x040001F2 RID: 498
|
||||
private bool hashing;
|
||||
|
||||
// Token: 0x040001F3 RID: 499
|
||||
private byte[] innerPad;
|
||||
|
||||
// Token: 0x040001F4 RID: 500
|
||||
private byte[] outerPad;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000025 RID: 37
|
||||
public sealed class KeyBuilder
|
||||
{
|
||||
// Token: 0x060001A5 RID: 421 RVA: 0x0000B4AC File Offset: 0x000096AC
|
||||
private KeyBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x1700005B RID: 91
|
||||
// (get) Token: 0x060001A6 RID: 422 RVA: 0x0000B4B4 File Offset: 0x000096B4
|
||||
private static RandomNumberGenerator Rng
|
||||
{
|
||||
get
|
||||
{
|
||||
if (KeyBuilder.rng == null)
|
||||
{
|
||||
KeyBuilder.rng = RandomNumberGenerator.Create();
|
||||
}
|
||||
return KeyBuilder.rng;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060001A7 RID: 423 RVA: 0x0000B4D0 File Offset: 0x000096D0
|
||||
public static byte[] Key(int size)
|
||||
{
|
||||
byte[] array = new byte[size];
|
||||
KeyBuilder.Rng.GetBytes(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060001A8 RID: 424 RVA: 0x0000B4F0 File Offset: 0x000096F0
|
||||
public static byte[] IV(int size)
|
||||
{
|
||||
byte[] array = new byte[size];
|
||||
KeyBuilder.Rng.GetBytes(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x040000AE RID: 174
|
||||
private static RandomNumberGenerator rng;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,395 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Mono.Xml;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x0200002B RID: 43
|
||||
public class KeyPairPersistence
|
||||
{
|
||||
// Token: 0x060001C9 RID: 457 RVA: 0x0000BE08 File Offset: 0x0000A008
|
||||
public KeyPairPersistence(CspParameters parameters)
|
||||
: this(parameters, null)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x060001CA RID: 458 RVA: 0x0000BE14 File Offset: 0x0000A014
|
||||
public KeyPairPersistence(CspParameters parameters, string keyPair)
|
||||
{
|
||||
if (parameters == null)
|
||||
{
|
||||
throw new ArgumentNullException("parameters");
|
||||
}
|
||||
this._params = this.Copy(parameters);
|
||||
this._keyvalue = keyPair;
|
||||
}
|
||||
|
||||
// Token: 0x1700005E RID: 94
|
||||
// (get) Token: 0x060001CC RID: 460 RVA: 0x0000BE5C File Offset: 0x0000A05C
|
||||
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: 0x1700005F RID: 95
|
||||
// (get) Token: 0x060001CD RID: 461 RVA: 0x0000BF00 File Offset: 0x0000A100
|
||||
// (set) Token: 0x060001CE RID: 462 RVA: 0x0000BF08 File Offset: 0x0000A108
|
||||
public string KeyValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._keyvalue;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.CanChange)
|
||||
{
|
||||
this._keyvalue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000060 RID: 96
|
||||
// (get) Token: 0x060001CF RID: 463 RVA: 0x0000BF1C File Offset: 0x0000A11C
|
||||
public CspParameters Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Copy(this._params);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060001D0 RID: 464 RVA: 0x0000BF2C File Offset: 0x0000A12C
|
||||
public bool Load()
|
||||
{
|
||||
bool flag = File.Exists(this.Filename);
|
||||
if (flag)
|
||||
{
|
||||
using (StreamReader streamReader = File.OpenText(this.Filename))
|
||||
{
|
||||
this.FromXml(streamReader.ReadToEnd());
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x060001D1 RID: 465 RVA: 0x0000BF94 File Offset: 0x0000A194
|
||||
public void Save()
|
||||
{
|
||||
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: 0x060001D2 RID: 466 RVA: 0x0000C024 File Offset: 0x0000A224
|
||||
public void Remove()
|
||||
{
|
||||
File.Delete(this.Filename);
|
||||
}
|
||||
|
||||
// Token: 0x17000061 RID: 97
|
||||
// (get) Token: 0x060001D3 RID: 467 RVA: 0x0000C034 File Offset: 0x0000A234
|
||||
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: 0x17000062 RID: 98
|
||||
// (get) Token: 0x060001D4 RID: 468 RVA: 0x0000C158 File Offset: 0x0000A358
|
||||
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: 0x060001D5 RID: 469 RVA: 0x0000C27C File Offset: 0x0000A47C
|
||||
internal static bool _CanSecure(string root)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x060001D6 RID: 470 RVA: 0x0000C280 File Offset: 0x0000A480
|
||||
internal static bool _ProtectUser(string path)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x060001D7 RID: 471 RVA: 0x0000C284 File Offset: 0x0000A484
|
||||
internal static bool _ProtectMachine(string path)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x060001D8 RID: 472 RVA: 0x0000C288 File Offset: 0x0000A488
|
||||
internal static bool _IsUserProtected(string path)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x060001D9 RID: 473 RVA: 0x0000C28C File Offset: 0x0000A48C
|
||||
internal static bool _IsMachineProtected(string path)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x060001DA RID: 474 RVA: 0x0000C290 File Offset: 0x0000A490
|
||||
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: 0x060001DB RID: 475 RVA: 0x0000C2D0 File Offset: 0x0000A4D0
|
||||
private static bool ProtectUser(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._ProtectUser(path);
|
||||
}
|
||||
|
||||
// Token: 0x060001DC RID: 476 RVA: 0x0000C2E8 File Offset: 0x0000A4E8
|
||||
private static bool ProtectMachine(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._ProtectMachine(path);
|
||||
}
|
||||
|
||||
// Token: 0x060001DD RID: 477 RVA: 0x0000C300 File Offset: 0x0000A500
|
||||
private static bool IsUserProtected(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._IsUserProtected(path);
|
||||
}
|
||||
|
||||
// Token: 0x060001DE RID: 478 RVA: 0x0000C318 File Offset: 0x0000A518
|
||||
private static bool IsMachineProtected(string path)
|
||||
{
|
||||
return !KeyPairPersistence.CanSecure(path) || KeyPairPersistence._IsMachineProtected(path);
|
||||
}
|
||||
|
||||
// Token: 0x17000063 RID: 99
|
||||
// (get) Token: 0x060001DF RID: 479 RVA: 0x0000C330 File Offset: 0x0000A530
|
||||
private bool CanChange
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._keyvalue == null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000064 RID: 100
|
||||
// (get) Token: 0x060001E0 RID: 480 RVA: 0x0000C33C File Offset: 0x0000A53C
|
||||
private bool UseDefaultKeyContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._params.Flags & CspProviderFlags.UseDefaultKeyContainer) == CspProviderFlags.UseDefaultKeyContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000065 RID: 101
|
||||
// (get) Token: 0x060001E1 RID: 481 RVA: 0x0000C350 File Offset: 0x0000A550
|
||||
private bool UseMachineKeyStore
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._params.Flags & CspProviderFlags.UseMachineKeyStore) == CspProviderFlags.UseMachineKeyStore;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000066 RID: 102
|
||||
// (get) Token: 0x060001E2 RID: 482 RVA: 0x0000C364 File Offset: 0x0000A564
|
||||
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: 0x060001E3 RID: 483 RVA: 0x0000C414 File Offset: 0x0000A614
|
||||
private CspParameters Copy(CspParameters p)
|
||||
{
|
||||
return new CspParameters(p.ProviderType, p.ProviderName, p.KeyContainerName)
|
||||
{
|
||||
KeyNumber = p.KeyNumber,
|
||||
Flags = p.Flags
|
||||
};
|
||||
}
|
||||
|
||||
// Token: 0x060001E4 RID: 484 RVA: 0x0000C454 File Offset: 0x0000A654
|
||||
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: 0x060001E5 RID: 485 RVA: 0x0000C4C0 File Offset: 0x0000A6C0
|
||||
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: 0x040000C0 RID: 192
|
||||
private static bool _userPathExists = false;
|
||||
|
||||
// Token: 0x040000C1 RID: 193
|
||||
private static string _userPath;
|
||||
|
||||
// Token: 0x040000C2 RID: 194
|
||||
private static bool _machinePathExists = false;
|
||||
|
||||
// Token: 0x040000C3 RID: 195
|
||||
private static string _machinePath;
|
||||
|
||||
// Token: 0x040000C4 RID: 196
|
||||
private CspParameters _params;
|
||||
|
||||
// Token: 0x040000C5 RID: 197
|
||||
private string _keyvalue;
|
||||
|
||||
// Token: 0x040000C6 RID: 198
|
||||
private string _filename;
|
||||
|
||||
// Token: 0x040000C7 RID: 199
|
||||
private string _container;
|
||||
|
||||
// Token: 0x040000C8 RID: 200
|
||||
private static object lockobj = new object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x0200002C RID: 44
|
||||
public abstract class MD2 : HashAlgorithm
|
||||
{
|
||||
// Token: 0x060001E6 RID: 486 RVA: 0x0000C5A4 File Offset: 0x0000A7A4
|
||||
protected MD2()
|
||||
{
|
||||
this.HashSizeValue = 128;
|
||||
}
|
||||
|
||||
// Token: 0x060001E7 RID: 487 RVA: 0x0000C5B8 File Offset: 0x0000A7B8
|
||||
public new static MD2 Create()
|
||||
{
|
||||
return MD2.Create("MD2");
|
||||
}
|
||||
|
||||
// Token: 0x060001E8 RID: 488 RVA: 0x0000C5C4 File Offset: 0x0000A7C4
|
||||
public new static MD2 Create(string hashName)
|
||||
{
|
||||
object obj = CryptoConfig.CreateFromName(hashName);
|
||||
if (obj == null)
|
||||
{
|
||||
obj = new MD2Managed();
|
||||
}
|
||||
return (MD2)obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x0200002D RID: 45
|
||||
public class MD2Managed : MD2
|
||||
{
|
||||
// Token: 0x060001E9 RID: 489 RVA: 0x0000C5EC File Offset: 0x0000A7EC
|
||||
public MD2Managed()
|
||||
{
|
||||
this.state = new byte[16];
|
||||
this.checksum = new byte[16];
|
||||
this.buffer = new byte[16];
|
||||
this.x = new byte[48];
|
||||
this.Initialize();
|
||||
}
|
||||
|
||||
// Token: 0x060001EB RID: 491 RVA: 0x0000C658 File Offset: 0x0000A858
|
||||
private byte[] Padding(int nLength)
|
||||
{
|
||||
if (nLength > 0)
|
||||
{
|
||||
byte[] array = new byte[nLength];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] = (byte)nLength;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x060001EC RID: 492 RVA: 0x0000C690 File Offset: 0x0000A890
|
||||
public override void Initialize()
|
||||
{
|
||||
this.count = 0;
|
||||
Array.Clear(this.state, 0, 16);
|
||||
Array.Clear(this.checksum, 0, 16);
|
||||
Array.Clear(this.buffer, 0, 16);
|
||||
Array.Clear(this.x, 0, 48);
|
||||
}
|
||||
|
||||
// Token: 0x060001ED RID: 493 RVA: 0x0000C6DC File Offset: 0x0000A8DC
|
||||
protected override void HashCore(byte[] array, int ibStart, int cbSize)
|
||||
{
|
||||
int num = this.count;
|
||||
this.count = (num + cbSize) & 15;
|
||||
int num2 = 16 - num;
|
||||
int num3;
|
||||
if (cbSize >= num2)
|
||||
{
|
||||
Buffer.BlockCopy(array, ibStart, this.buffer, num, num2);
|
||||
this.MD2Transform(this.state, this.checksum, this.buffer, 0);
|
||||
num3 = num2;
|
||||
while (num3 + 15 < cbSize)
|
||||
{
|
||||
this.MD2Transform(this.state, this.checksum, array, num3);
|
||||
num3 += 16;
|
||||
}
|
||||
num = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
num3 = 0;
|
||||
}
|
||||
Buffer.BlockCopy(array, ibStart + num3, this.buffer, num, cbSize - num3);
|
||||
}
|
||||
|
||||
// Token: 0x060001EE RID: 494 RVA: 0x0000C778 File Offset: 0x0000A978
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
int num = this.count;
|
||||
int num2 = 16 - num;
|
||||
if (num2 > 0)
|
||||
{
|
||||
this.HashCore(this.Padding(num2), 0, num2);
|
||||
}
|
||||
this.HashCore(this.checksum, 0, 16);
|
||||
byte[] array = (byte[])this.state.Clone();
|
||||
this.Initialize();
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x060001EF RID: 495 RVA: 0x0000C7D0 File Offset: 0x0000A9D0
|
||||
private void MD2Transform(byte[] state, byte[] checksum, byte[] block, int index)
|
||||
{
|
||||
Buffer.BlockCopy(state, 0, this.x, 0, 16);
|
||||
Buffer.BlockCopy(block, index, this.x, 16, 16);
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
this.x[i + 32] = state[i] ^ block[index + i];
|
||||
}
|
||||
int num = 0;
|
||||
for (int j = 0; j < 18; j++)
|
||||
{
|
||||
for (int k = 0; k < 48; k++)
|
||||
{
|
||||
byte[] array = this.x;
|
||||
int num2 = k;
|
||||
num = (int)(array[num2] ^= MD2Managed.PI_SUBST[num]);
|
||||
}
|
||||
num = (num + j) & 255;
|
||||
}
|
||||
Buffer.BlockCopy(this.x, 0, state, 0, 16);
|
||||
num = (int)checksum[15];
|
||||
for (int l = 0; l < 16; l++)
|
||||
{
|
||||
int num3 = l;
|
||||
num = (int)(checksum[num3] ^= MD2Managed.PI_SUBST[(int)block[index + l] ^ num]);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x040000C9 RID: 201
|
||||
private byte[] state;
|
||||
|
||||
// Token: 0x040000CA RID: 202
|
||||
private byte[] checksum;
|
||||
|
||||
// Token: 0x040000CB RID: 203
|
||||
private byte[] buffer;
|
||||
|
||||
// Token: 0x040000CC RID: 204
|
||||
private int count;
|
||||
|
||||
// Token: 0x040000CD RID: 205
|
||||
private byte[] x;
|
||||
|
||||
// Token: 0x040000CE RID: 206
|
||||
private static readonly byte[] PI_SUBST = new byte[]
|
||||
{
|
||||
41, 46, 67, 201, 162, 216, 124, 1, 61, 54,
|
||||
84, 161, 236, 240, 6, 19, 98, 167, 5, 243,
|
||||
192, 199, 115, 140, 152, 147, 43, 217, 188, 76,
|
||||
130, 202, 30, 155, 87, 60, 253, 212, 224, 22,
|
||||
103, 66, 111, 24, 138, 23, 229, 18, 190, 78,
|
||||
196, 214, 218, 158, 222, 73, 160, 251, 245, 142,
|
||||
187, 47, 238, 122, 169, 104, 121, 145, 21, 178,
|
||||
7, 63, 148, 194, 16, 137, 11, 34, 95, 33,
|
||||
128, 127, 93, 154, 90, 144, 50, 39, 53, 62,
|
||||
204, 231, 191, 247, 151, 3, byte.MaxValue, 25, 48, 179,
|
||||
72, 165, 181, 209, 215, 94, 146, 42, 172, 86,
|
||||
170, 198, 79, 184, 56, 210, 150, 164, 125, 182,
|
||||
118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
|
||||
112, 89, 100, 113, 135, 32, 134, 91, 207, 101,
|
||||
230, 45, 168, 2, 27, 96, 37, 173, 174, 176,
|
||||
185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
|
||||
85, 71, 163, 35, 221, 81, 175, 58, 195, 92,
|
||||
249, 206, 186, 197, 234, 38, 44, 83, 13, 110,
|
||||
133, 40, 132, 9, 211, 223, 205, 244, 65, 129,
|
||||
77, 82, 106, 220, 55, 200, 108, 193, 171, 250,
|
||||
36, 225, 123, 8, 12, 189, 177, 74, 120, 136,
|
||||
149, 139, 227, 99, 232, 109, 233, 203, 213, 254,
|
||||
59, 0, 29, 57, 242, 239, 183, 14, 102, 88,
|
||||
208, 228, 166, 119, 114, 248, 235, 117, 75, 10,
|
||||
49, 68, 80, 180, 143, 237, 31, 26, 219, 153,
|
||||
141, 51, 159, 17, 131, 20
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x0200002E RID: 46
|
||||
public abstract class MD4 : HashAlgorithm
|
||||
{
|
||||
// Token: 0x060001F0 RID: 496 RVA: 0x0000C8C8 File Offset: 0x0000AAC8
|
||||
protected MD4()
|
||||
{
|
||||
this.HashSizeValue = 128;
|
||||
}
|
||||
|
||||
// Token: 0x060001F1 RID: 497 RVA: 0x0000C8DC File Offset: 0x0000AADC
|
||||
public new static MD4 Create()
|
||||
{
|
||||
return MD4.Create("MD4");
|
||||
}
|
||||
|
||||
// Token: 0x060001F2 RID: 498 RVA: 0x0000C8E8 File Offset: 0x0000AAE8
|
||||
public new static MD4 Create(string hashName)
|
||||
{
|
||||
object obj = CryptoConfig.CreateFromName(hashName);
|
||||
if (obj == null)
|
||||
{
|
||||
obj = new MD4Managed();
|
||||
}
|
||||
return (MD4)obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x0200002F RID: 47
|
||||
public class MD4Managed : MD4
|
||||
{
|
||||
// Token: 0x060001F3 RID: 499 RVA: 0x0000C910 File Offset: 0x0000AB10
|
||||
public MD4Managed()
|
||||
{
|
||||
this.state = new uint[4];
|
||||
this.count = new uint[2];
|
||||
this.buffer = new byte[64];
|
||||
this.digest = new byte[16];
|
||||
this.x = new uint[16];
|
||||
this.Initialize();
|
||||
}
|
||||
|
||||
// Token: 0x060001F4 RID: 500 RVA: 0x0000C968 File Offset: 0x0000AB68
|
||||
public override void Initialize()
|
||||
{
|
||||
this.count[0] = 0U;
|
||||
this.count[1] = 0U;
|
||||
this.state[0] = 1732584193U;
|
||||
this.state[1] = 4023233417U;
|
||||
this.state[2] = 2562383102U;
|
||||
this.state[3] = 271733878U;
|
||||
Array.Clear(this.buffer, 0, 64);
|
||||
Array.Clear(this.x, 0, 16);
|
||||
}
|
||||
|
||||
// Token: 0x060001F5 RID: 501 RVA: 0x0000C9D8 File Offset: 0x0000ABD8
|
||||
protected override void HashCore(byte[] array, int ibStart, int cbSize)
|
||||
{
|
||||
int num = (int)((this.count[0] >> 3) & 63U);
|
||||
this.count[0] += (uint)((uint)cbSize << 3);
|
||||
if ((ulong)this.count[0] < (ulong)((long)((long)cbSize << 3)))
|
||||
{
|
||||
this.count[1] += 1U;
|
||||
}
|
||||
this.count[1] += (uint)(cbSize >> 29);
|
||||
int num2 = 64 - num;
|
||||
int num3 = 0;
|
||||
if (cbSize >= num2)
|
||||
{
|
||||
Buffer.BlockCopy(array, ibStart, this.buffer, num, num2);
|
||||
this.MD4Transform(this.state, this.buffer, 0);
|
||||
num3 = num2;
|
||||
while (num3 + 63 < cbSize)
|
||||
{
|
||||
this.MD4Transform(this.state, array, num3);
|
||||
num3 += 64;
|
||||
}
|
||||
num = 0;
|
||||
}
|
||||
Buffer.BlockCopy(array, ibStart + num3, this.buffer, num, cbSize - num3);
|
||||
}
|
||||
|
||||
// Token: 0x060001F6 RID: 502 RVA: 0x0000CAA8 File Offset: 0x0000ACA8
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
byte[] array = new byte[8];
|
||||
this.Encode(array, this.count);
|
||||
uint num = (this.count[0] >> 3) & 63U;
|
||||
int num2 = (int)((num >= 56U) ? (120U - num) : (56U - num));
|
||||
this.HashCore(this.Padding(num2), 0, num2);
|
||||
this.HashCore(array, 0, 8);
|
||||
this.Encode(this.digest, this.state);
|
||||
this.Initialize();
|
||||
return this.digest;
|
||||
}
|
||||
|
||||
// Token: 0x060001F7 RID: 503 RVA: 0x0000CB24 File Offset: 0x0000AD24
|
||||
private byte[] Padding(int nLength)
|
||||
{
|
||||
if (nLength > 0)
|
||||
{
|
||||
byte[] array = new byte[nLength];
|
||||
array[0] = 128;
|
||||
return array;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x060001F8 RID: 504 RVA: 0x0000CB4C File Offset: 0x0000AD4C
|
||||
private uint F(uint x, uint y, uint z)
|
||||
{
|
||||
return (x & y) | (~x & z);
|
||||
}
|
||||
|
||||
// Token: 0x060001F9 RID: 505 RVA: 0x0000CB58 File Offset: 0x0000AD58
|
||||
private uint G(uint x, uint y, uint z)
|
||||
{
|
||||
return (x & y) | (x & z) | (y & z);
|
||||
}
|
||||
|
||||
// Token: 0x060001FA RID: 506 RVA: 0x0000CB68 File Offset: 0x0000AD68
|
||||
private uint H(uint x, uint y, uint z)
|
||||
{
|
||||
return x ^ y ^ z;
|
||||
}
|
||||
|
||||
// Token: 0x060001FB RID: 507 RVA: 0x0000CB70 File Offset: 0x0000AD70
|
||||
private uint ROL(uint x, byte n)
|
||||
{
|
||||
return (x << (int)n) | (x >> (int)(32 - n));
|
||||
}
|
||||
|
||||
// Token: 0x060001FC RID: 508 RVA: 0x0000CB84 File Offset: 0x0000AD84
|
||||
private void FF(ref uint a, uint b, uint c, uint d, uint x, byte s)
|
||||
{
|
||||
a += this.F(b, c, d) + x;
|
||||
a = this.ROL(a, s);
|
||||
}
|
||||
|
||||
// Token: 0x060001FD RID: 509 RVA: 0x0000CBA4 File Offset: 0x0000ADA4
|
||||
private void GG(ref uint a, uint b, uint c, uint d, uint x, byte s)
|
||||
{
|
||||
a += this.G(b, c, d) + x + 1518500249U;
|
||||
a = this.ROL(a, s);
|
||||
}
|
||||
|
||||
// Token: 0x060001FE RID: 510 RVA: 0x0000CBD8 File Offset: 0x0000ADD8
|
||||
private void HH(ref uint a, uint b, uint c, uint d, uint x, byte s)
|
||||
{
|
||||
a += this.H(b, c, d) + x + 1859775393U;
|
||||
a = this.ROL(a, s);
|
||||
}
|
||||
|
||||
// Token: 0x060001FF RID: 511 RVA: 0x0000CC0C File Offset: 0x0000AE0C
|
||||
private void Encode(byte[] output, uint[] input)
|
||||
{
|
||||
int num = 0;
|
||||
for (int i = 0; i < output.Length; i += 4)
|
||||
{
|
||||
output[i] = (byte)input[num];
|
||||
output[i + 1] = (byte)(input[num] >> 8);
|
||||
output[i + 2] = (byte)(input[num] >> 16);
|
||||
output[i + 3] = (byte)(input[num] >> 24);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000200 RID: 512 RVA: 0x0000CC60 File Offset: 0x0000AE60
|
||||
private void Decode(uint[] output, byte[] input, int index)
|
||||
{
|
||||
int i = 0;
|
||||
int num = index;
|
||||
while (i < output.Length)
|
||||
{
|
||||
output[i] = (uint)((int)input[num] | ((int)input[num + 1] << 8) | ((int)input[num + 2] << 16) | ((int)input[num + 3] << 24));
|
||||
i++;
|
||||
num += 4;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000201 RID: 513 RVA: 0x0000CCA8 File Offset: 0x0000AEA8
|
||||
private void MD4Transform(uint[] state, byte[] block, int index)
|
||||
{
|
||||
uint num = state[0];
|
||||
uint num2 = state[1];
|
||||
uint num3 = state[2];
|
||||
uint num4 = state[3];
|
||||
this.Decode(this.x, block, index);
|
||||
this.FF(ref num, num2, num3, num4, this.x[0], 3);
|
||||
this.FF(ref num4, num, num2, num3, this.x[1], 7);
|
||||
this.FF(ref num3, num4, num, num2, this.x[2], 11);
|
||||
this.FF(ref num2, num3, num4, num, this.x[3], 19);
|
||||
this.FF(ref num, num2, num3, num4, this.x[4], 3);
|
||||
this.FF(ref num4, num, num2, num3, this.x[5], 7);
|
||||
this.FF(ref num3, num4, num, num2, this.x[6], 11);
|
||||
this.FF(ref num2, num3, num4, num, this.x[7], 19);
|
||||
this.FF(ref num, num2, num3, num4, this.x[8], 3);
|
||||
this.FF(ref num4, num, num2, num3, this.x[9], 7);
|
||||
this.FF(ref num3, num4, num, num2, this.x[10], 11);
|
||||
this.FF(ref num2, num3, num4, num, this.x[11], 19);
|
||||
this.FF(ref num, num2, num3, num4, this.x[12], 3);
|
||||
this.FF(ref num4, num, num2, num3, this.x[13], 7);
|
||||
this.FF(ref num3, num4, num, num2, this.x[14], 11);
|
||||
this.FF(ref num2, num3, num4, num, this.x[15], 19);
|
||||
this.GG(ref num, num2, num3, num4, this.x[0], 3);
|
||||
this.GG(ref num4, num, num2, num3, this.x[4], 5);
|
||||
this.GG(ref num3, num4, num, num2, this.x[8], 9);
|
||||
this.GG(ref num2, num3, num4, num, this.x[12], 13);
|
||||
this.GG(ref num, num2, num3, num4, this.x[1], 3);
|
||||
this.GG(ref num4, num, num2, num3, this.x[5], 5);
|
||||
this.GG(ref num3, num4, num, num2, this.x[9], 9);
|
||||
this.GG(ref num2, num3, num4, num, this.x[13], 13);
|
||||
this.GG(ref num, num2, num3, num4, this.x[2], 3);
|
||||
this.GG(ref num4, num, num2, num3, this.x[6], 5);
|
||||
this.GG(ref num3, num4, num, num2, this.x[10], 9);
|
||||
this.GG(ref num2, num3, num4, num, this.x[14], 13);
|
||||
this.GG(ref num, num2, num3, num4, this.x[3], 3);
|
||||
this.GG(ref num4, num, num2, num3, this.x[7], 5);
|
||||
this.GG(ref num3, num4, num, num2, this.x[11], 9);
|
||||
this.GG(ref num2, num3, num4, num, this.x[15], 13);
|
||||
this.HH(ref num, num2, num3, num4, this.x[0], 3);
|
||||
this.HH(ref num4, num, num2, num3, this.x[8], 9);
|
||||
this.HH(ref num3, num4, num, num2, this.x[4], 11);
|
||||
this.HH(ref num2, num3, num4, num, this.x[12], 15);
|
||||
this.HH(ref num, num2, num3, num4, this.x[2], 3);
|
||||
this.HH(ref num4, num, num2, num3, this.x[10], 9);
|
||||
this.HH(ref num3, num4, num, num2, this.x[6], 11);
|
||||
this.HH(ref num2, num3, num4, num, this.x[14], 15);
|
||||
this.HH(ref num, num2, num3, num4, this.x[1], 3);
|
||||
this.HH(ref num4, num, num2, num3, this.x[9], 9);
|
||||
this.HH(ref num3, num4, num, num2, this.x[5], 11);
|
||||
this.HH(ref num2, num3, num4, num, this.x[13], 15);
|
||||
this.HH(ref num, num2, num3, num4, this.x[3], 3);
|
||||
this.HH(ref num4, num, num2, num3, this.x[11], 9);
|
||||
this.HH(ref num3, num4, num, num2, this.x[7], 11);
|
||||
this.HH(ref num2, num3, num4, num, this.x[15], 15);
|
||||
state[0] += num;
|
||||
state[1] += num2;
|
||||
state[2] += num3;
|
||||
state[3] += num4;
|
||||
}
|
||||
|
||||
// Token: 0x040000CF RID: 207
|
||||
private const int S11 = 3;
|
||||
|
||||
// Token: 0x040000D0 RID: 208
|
||||
private const int S12 = 7;
|
||||
|
||||
// Token: 0x040000D1 RID: 209
|
||||
private const int S13 = 11;
|
||||
|
||||
// Token: 0x040000D2 RID: 210
|
||||
private const int S14 = 19;
|
||||
|
||||
// Token: 0x040000D3 RID: 211
|
||||
private const int S21 = 3;
|
||||
|
||||
// Token: 0x040000D4 RID: 212
|
||||
private const int S22 = 5;
|
||||
|
||||
// Token: 0x040000D5 RID: 213
|
||||
private const int S23 = 9;
|
||||
|
||||
// Token: 0x040000D6 RID: 214
|
||||
private const int S24 = 13;
|
||||
|
||||
// Token: 0x040000D7 RID: 215
|
||||
private const int S31 = 3;
|
||||
|
||||
// Token: 0x040000D8 RID: 216
|
||||
private const int S32 = 9;
|
||||
|
||||
// Token: 0x040000D9 RID: 217
|
||||
private const int S33 = 11;
|
||||
|
||||
// Token: 0x040000DA RID: 218
|
||||
private const int S34 = 15;
|
||||
|
||||
// Token: 0x040000DB RID: 219
|
||||
private uint[] state;
|
||||
|
||||
// Token: 0x040000DC RID: 220
|
||||
private byte[] buffer;
|
||||
|
||||
// Token: 0x040000DD RID: 221
|
||||
private uint[] count;
|
||||
|
||||
// Token: 0x040000DE RID: 222
|
||||
private uint[] x;
|
||||
|
||||
// Token: 0x040000DF RID: 223
|
||||
private byte[] digest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using Mono.Security.Protocol.Tls;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000075 RID: 117
|
||||
internal class MD5SHA1 : HashAlgorithm
|
||||
{
|
||||
// Token: 0x06000431 RID: 1073 RVA: 0x0001B19C File Offset: 0x0001939C
|
||||
public MD5SHA1()
|
||||
{
|
||||
this.md5 = MD5.Create();
|
||||
this.sha = SHA1.Create();
|
||||
this.HashSizeValue = this.md5.HashSize + this.sha.HashSize;
|
||||
}
|
||||
|
||||
// Token: 0x06000432 RID: 1074 RVA: 0x0001B1E4 File Offset: 0x000193E4
|
||||
public override void Initialize()
|
||||
{
|
||||
this.md5.Initialize();
|
||||
this.sha.Initialize();
|
||||
this.hashing = false;
|
||||
}
|
||||
|
||||
// Token: 0x06000433 RID: 1075 RVA: 0x0001B204 File Offset: 0x00019404
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
if (!this.hashing)
|
||||
{
|
||||
this.hashing = true;
|
||||
}
|
||||
this.md5.TransformFinalBlock(new byte[0], 0, 0);
|
||||
this.sha.TransformFinalBlock(new byte[0], 0, 0);
|
||||
byte[] array = new byte[36];
|
||||
Buffer.BlockCopy(this.md5.Hash, 0, array, 0, 16);
|
||||
Buffer.BlockCopy(this.sha.Hash, 0, array, 16, 20);
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000434 RID: 1076 RVA: 0x0001B280 File Offset: 0x00019480
|
||||
protected override void HashCore(byte[] array, int ibStart, int cbSize)
|
||||
{
|
||||
if (!this.hashing)
|
||||
{
|
||||
this.hashing = true;
|
||||
}
|
||||
this.md5.TransformBlock(array, ibStart, cbSize, array, ibStart);
|
||||
this.sha.TransformBlock(array, ibStart, cbSize, array, ibStart);
|
||||
}
|
||||
|
||||
// Token: 0x06000435 RID: 1077 RVA: 0x0001B2C4 File Offset: 0x000194C4
|
||||
public byte[] CreateSignature(RSA rsa)
|
||||
{
|
||||
if (rsa == null)
|
||||
{
|
||||
throw new CryptographicUnexpectedOperationException("missing key");
|
||||
}
|
||||
RSASslSignatureFormatter rsasslSignatureFormatter = new RSASslSignatureFormatter(rsa);
|
||||
rsasslSignatureFormatter.SetHashAlgorithm("MD5SHA1");
|
||||
return rsasslSignatureFormatter.CreateSignature(this.Hash);
|
||||
}
|
||||
|
||||
// Token: 0x06000436 RID: 1078 RVA: 0x0001B300 File Offset: 0x00019500
|
||||
public bool VerifySignature(RSA rsa, byte[] rgbSignature)
|
||||
{
|
||||
if (rsa == null)
|
||||
{
|
||||
throw new CryptographicUnexpectedOperationException("missing key");
|
||||
}
|
||||
if (rgbSignature == null)
|
||||
{
|
||||
throw new ArgumentNullException("rgbSignature");
|
||||
}
|
||||
RSASslSignatureDeformatter rsasslSignatureDeformatter = new RSASslSignatureDeformatter(rsa);
|
||||
rsasslSignatureDeformatter.SetHashAlgorithm("MD5SHA1");
|
||||
return rsasslSignatureDeformatter.VerifySignature(this.Hash, rgbSignature);
|
||||
}
|
||||
|
||||
// Token: 0x040001F5 RID: 501
|
||||
private HashAlgorithm md5;
|
||||
|
||||
// Token: 0x040001F6 RID: 502
|
||||
private HashAlgorithm sha;
|
||||
|
||||
// Token: 0x040001F7 RID: 503
|
||||
private bool hashing;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,394 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000030 RID: 48
|
||||
public sealed class PKCS1
|
||||
{
|
||||
// Token: 0x06000202 RID: 514 RVA: 0x0000D0F4 File Offset: 0x0000B2F4
|
||||
private PKCS1()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000204 RID: 516 RVA: 0x0000D168 File Offset: 0x0000B368
|
||||
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: 0x06000205 RID: 517 RVA: 0x0000D1A8 File Offset: 0x0000B3A8
|
||||
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: 0x06000206 RID: 518 RVA: 0x0000D1E0 File Offset: 0x0000B3E0
|
||||
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: 0x06000207 RID: 519 RVA: 0x0000D238 File Offset: 0x0000B438
|
||||
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: 0x06000208 RID: 520 RVA: 0x0000D260 File Offset: 0x0000B460
|
||||
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: 0x06000209 RID: 521 RVA: 0x0000D288 File Offset: 0x0000B488
|
||||
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: 0x0600020A RID: 522 RVA: 0x0000D2D8 File Offset: 0x0000B4D8
|
||||
public static byte[] RSAEP(RSA rsa, byte[] m)
|
||||
{
|
||||
return rsa.EncryptValue(m);
|
||||
}
|
||||
|
||||
// Token: 0x0600020B RID: 523 RVA: 0x0000D2E4 File Offset: 0x0000B4E4
|
||||
public static byte[] RSADP(RSA rsa, byte[] c)
|
||||
{
|
||||
return rsa.DecryptValue(c);
|
||||
}
|
||||
|
||||
// Token: 0x0600020C RID: 524 RVA: 0x0000D2F0 File Offset: 0x0000B4F0
|
||||
public static byte[] RSASP1(RSA rsa, byte[] m)
|
||||
{
|
||||
return rsa.DecryptValue(m);
|
||||
}
|
||||
|
||||
// Token: 0x0600020D RID: 525 RVA: 0x0000D2FC File Offset: 0x0000B4FC
|
||||
public static byte[] RSAVP1(RSA rsa, byte[] s)
|
||||
{
|
||||
return rsa.EncryptValue(s);
|
||||
}
|
||||
|
||||
// Token: 0x0600020E RID: 526 RVA: 0x0000D308 File Offset: 0x0000B508
|
||||
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: 0x0600020F RID: 527 RVA: 0x0000D420 File Offset: 0x0000B620
|
||||
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: 0x06000210 RID: 528 RVA: 0x0000D56C File Offset: 0x0000B76C
|
||||
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: 0x06000211 RID: 529 RVA: 0x0000D5F8 File Offset: 0x0000B7F8
|
||||
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: 0x06000212 RID: 530 RVA: 0x0000D6A8 File Offset: 0x0000B8A8
|
||||
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: 0x06000213 RID: 531 RVA: 0x0000D6E4 File Offset: 0x0000B8E4
|
||||
public static bool Verify_v15(RSA rsa, HashAlgorithm hash, byte[] hashValue, byte[] signature)
|
||||
{
|
||||
return PKCS1.Verify_v15(rsa, hash, hashValue, signature, false);
|
||||
}
|
||||
|
||||
// Token: 0x06000214 RID: 532 RVA: 0x0000D6F0 File Offset: 0x0000B8F0
|
||||
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: 0x06000215 RID: 533 RVA: 0x0000D7B4 File Offset: 0x0000B9B4
|
||||
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: 0x06000216 RID: 534 RVA: 0x0000D8C0 File Offset: 0x0000BAC0
|
||||
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: 0x040000E0 RID: 224
|
||||
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: 0x040000E1 RID: 225
|
||||
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: 0x040000E2 RID: 226
|
||||
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: 0x040000E3 RID: 227
|
||||
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: 0x02000031 RID: 49
|
||||
public sealed class PKCS8
|
||||
{
|
||||
// Token: 0x06000217 RID: 535 RVA: 0x0000D978 File Offset: 0x0000BB78
|
||||
private PKCS8()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x06000218 RID: 536 RVA: 0x0000D980 File Offset: 0x0000BB80
|
||||
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: 0x02000032 RID: 50
|
||||
public enum KeyInfo
|
||||
{
|
||||
// Token: 0x040000E5 RID: 229
|
||||
PrivateKey,
|
||||
// Token: 0x040000E6 RID: 230
|
||||
EncryptedPrivateKey,
|
||||
// Token: 0x040000E7 RID: 231
|
||||
Unknown
|
||||
}
|
||||
|
||||
// Token: 0x02000033 RID: 51
|
||||
public class PrivateKeyInfo
|
||||
{
|
||||
// Token: 0x06000219 RID: 537 RVA: 0x0000DA24 File Offset: 0x0000BC24
|
||||
public PrivateKeyInfo()
|
||||
{
|
||||
this._version = 0;
|
||||
this._list = new ArrayList();
|
||||
}
|
||||
|
||||
// Token: 0x0600021A RID: 538 RVA: 0x0000DA40 File Offset: 0x0000BC40
|
||||
public PrivateKeyInfo(byte[] data)
|
||||
: this()
|
||||
{
|
||||
this.Decode(data);
|
||||
}
|
||||
|
||||
// Token: 0x17000067 RID: 103
|
||||
// (get) Token: 0x0600021B RID: 539 RVA: 0x0000DA50 File Offset: 0x0000BC50
|
||||
// (set) Token: 0x0600021C RID: 540 RVA: 0x0000DA58 File Offset: 0x0000BC58
|
||||
public string Algorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._algorithm;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._algorithm = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000068 RID: 104
|
||||
// (get) Token: 0x0600021D RID: 541 RVA: 0x0000DA64 File Offset: 0x0000BC64
|
||||
public ArrayList Attributes
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._list;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000069 RID: 105
|
||||
// (get) Token: 0x0600021E RID: 542 RVA: 0x0000DA6C File Offset: 0x0000BC6C
|
||||
// (set) Token: 0x0600021F RID: 543 RVA: 0x0000DA8C File Offset: 0x0000BC8C
|
||||
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: 0x1700006A RID: 106
|
||||
// (get) Token: 0x06000220 RID: 544 RVA: 0x0000DABC File Offset: 0x0000BCBC
|
||||
// (set) Token: 0x06000221 RID: 545 RVA: 0x0000DAC4 File Offset: 0x0000BCC4
|
||||
public int Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._version;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("negative version");
|
||||
}
|
||||
this._version = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000222 RID: 546 RVA: 0x0000DAE0 File Offset: 0x0000BCE0
|
||||
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: 0x06000223 RID: 547 RVA: 0x0000DBE0 File Offset: 0x0000BDE0
|
||||
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: 0x06000224 RID: 548 RVA: 0x0000DCE8 File Offset: 0x0000BEE8
|
||||
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: 0x06000225 RID: 549 RVA: 0x0000DD1C File Offset: 0x0000BF1C
|
||||
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: 0x06000226 RID: 550 RVA: 0x0000DD5C File Offset: 0x0000BF5C
|
||||
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: 0x06000227 RID: 551 RVA: 0x0000DEFC File Offset: 0x0000C0FC
|
||||
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: 0x06000228 RID: 552 RVA: 0x0000DFCC File Offset: 0x0000C1CC
|
||||
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: 0x06000229 RID: 553 RVA: 0x0000E01C File Offset: 0x0000C21C
|
||||
public static byte[] Encode(DSA dsa)
|
||||
{
|
||||
return ASN1Convert.FromUnsignedBigInteger(dsa.ExportParameters(true).X).GetBytes();
|
||||
}
|
||||
|
||||
// Token: 0x0600022A RID: 554 RVA: 0x0000E044 File Offset: 0x0000C244
|
||||
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: 0x040000E8 RID: 232
|
||||
private int _version;
|
||||
|
||||
// Token: 0x040000E9 RID: 233
|
||||
private string _algorithm;
|
||||
|
||||
// Token: 0x040000EA RID: 234
|
||||
private byte[] _key;
|
||||
|
||||
// Token: 0x040000EB RID: 235
|
||||
private ArrayList _list;
|
||||
}
|
||||
|
||||
// Token: 0x02000034 RID: 52
|
||||
public class EncryptedPrivateKeyInfo
|
||||
{
|
||||
// Token: 0x0600022B RID: 555 RVA: 0x0000E090 File Offset: 0x0000C290
|
||||
public EncryptedPrivateKeyInfo()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x0600022C RID: 556 RVA: 0x0000E098 File Offset: 0x0000C298
|
||||
public EncryptedPrivateKeyInfo(byte[] data)
|
||||
: this()
|
||||
{
|
||||
this.Decode(data);
|
||||
}
|
||||
|
||||
// Token: 0x1700006B RID: 107
|
||||
// (get) Token: 0x0600022D RID: 557 RVA: 0x0000E0A8 File Offset: 0x0000C2A8
|
||||
// (set) Token: 0x0600022E RID: 558 RVA: 0x0000E0B0 File Offset: 0x0000C2B0
|
||||
public string Algorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._algorithm;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._algorithm = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700006C RID: 108
|
||||
// (get) Token: 0x0600022F RID: 559 RVA: 0x0000E0BC File Offset: 0x0000C2BC
|
||||
// (set) Token: 0x06000230 RID: 560 RVA: 0x0000E0E0 File Offset: 0x0000C2E0
|
||||
public byte[] EncryptedData
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._data != null) ? ((byte[])this._data.Clone()) : null;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._data = ((value != null) ? ((byte[])value.Clone()) : null);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700006D RID: 109
|
||||
// (get) Token: 0x06000231 RID: 561 RVA: 0x0000E100 File Offset: 0x0000C300
|
||||
// (set) Token: 0x06000232 RID: 562 RVA: 0x0000E148 File Offset: 0x0000C348
|
||||
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: 0x1700006E RID: 110
|
||||
// (get) Token: 0x06000233 RID: 563 RVA: 0x0000E15C File Offset: 0x0000C35C
|
||||
// (set) Token: 0x06000234 RID: 564 RVA: 0x0000E164 File Offset: 0x0000C364
|
||||
public int IterationCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._iterations;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("IterationCount", "Negative");
|
||||
}
|
||||
this._iterations = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000235 RID: 565 RVA: 0x0000E184 File Offset: 0x0000C384
|
||||
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: 0x06000236 RID: 566 RVA: 0x0000E2B4 File Offset: 0x0000C4B4
|
||||
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: 0x040000EC RID: 236
|
||||
private string _algorithm;
|
||||
|
||||
// Token: 0x040000ED RID: 237
|
||||
private byte[] _salt;
|
||||
|
||||
// Token: 0x040000EE RID: 238
|
||||
private int _iterations;
|
||||
|
||||
// Token: 0x040000EF RID: 239
|
||||
private byte[] _data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000035 RID: 53
|
||||
public abstract class RC4 : SymmetricAlgorithm
|
||||
{
|
||||
// Token: 0x06000237 RID: 567 RVA: 0x0000E374 File Offset: 0x0000C574
|
||||
public RC4()
|
||||
{
|
||||
this.KeySizeValue = 128;
|
||||
this.BlockSizeValue = 64;
|
||||
this.FeedbackSizeValue = this.BlockSizeValue;
|
||||
this.LegalBlockSizesValue = RC4.s_legalBlockSizes;
|
||||
this.LegalKeySizesValue = RC4.s_legalKeySizes;
|
||||
}
|
||||
|
||||
// Token: 0x1700006F RID: 111
|
||||
// (get) Token: 0x06000239 RID: 569 RVA: 0x0000E3EC File Offset: 0x0000C5EC
|
||||
// (set) Token: 0x0600023A RID: 570 RVA: 0x0000E3F4 File Offset: 0x0000C5F4
|
||||
public override byte[] IV
|
||||
{
|
||||
get
|
||||
{
|
||||
return new byte[0];
|
||||
}
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600023B RID: 571 RVA: 0x0000E3F8 File Offset: 0x0000C5F8
|
||||
public new static RC4 Create()
|
||||
{
|
||||
return RC4.Create("RC4");
|
||||
}
|
||||
|
||||
// Token: 0x0600023C RID: 572 RVA: 0x0000E404 File Offset: 0x0000C604
|
||||
public new static RC4 Create(string algName)
|
||||
{
|
||||
object obj = CryptoConfig.CreateFromName(algName);
|
||||
if (obj == null)
|
||||
{
|
||||
obj = new ARC4Managed();
|
||||
}
|
||||
return (RC4)obj;
|
||||
}
|
||||
|
||||
// Token: 0x040000F0 RID: 240
|
||||
private static KeySizes[] s_legalBlockSizes = new KeySizes[]
|
||||
{
|
||||
new KeySizes(64, 64, 0)
|
||||
};
|
||||
|
||||
// Token: 0x040000F1 RID: 241
|
||||
private static KeySizes[] s_legalKeySizes = new KeySizes[]
|
||||
{
|
||||
new KeySizes(40, 2048, 8)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,524 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Mono.Math;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000036 RID: 54
|
||||
public class RSAManaged : RSA
|
||||
{
|
||||
// Token: 0x0600023D RID: 573 RVA: 0x0000E42C File Offset: 0x0000C62C
|
||||
public RSAManaged()
|
||||
: this(1024)
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x0600023E RID: 574 RVA: 0x0000E43C File Offset: 0x0000C63C
|
||||
public RSAManaged(int keySize)
|
||||
{
|
||||
this.LegalKeySizesValue = new KeySizes[1];
|
||||
this.LegalKeySizesValue[0] = new KeySizes(384, 16384, 8);
|
||||
base.KeySize = keySize;
|
||||
}
|
||||
|
||||
// Token: 0x14000001 RID: 1
|
||||
// (add) Token: 0x0600023F RID: 575 RVA: 0x0000E484 File Offset: 0x0000C684
|
||||
// (remove) Token: 0x06000240 RID: 576 RVA: 0x0000E4A0 File Offset: 0x0000C6A0
|
||||
public event RSAManaged.KeyGeneratedEventHandler KeyGenerated;
|
||||
|
||||
// Token: 0x06000241 RID: 577 RVA: 0x0000E4BC File Offset: 0x0000C6BC
|
||||
~RSAManaged()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
// Token: 0x06000242 RID: 578 RVA: 0x0000E4F8 File Offset: 0x0000C6F8
|
||||
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: 0x17000070 RID: 112
|
||||
// (get) Token: 0x06000243 RID: 579 RVA: 0x0000E69C File Offset: 0x0000C89C
|
||||
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: 0x17000071 RID: 113
|
||||
// (get) Token: 0x06000244 RID: 580 RVA: 0x0000E6D8 File Offset: 0x0000C8D8
|
||||
public override string KeyExchangeAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return "RSA-PKCS1-KeyEx";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000072 RID: 114
|
||||
// (get) Token: 0x06000245 RID: 581 RVA: 0x0000E6E0 File Offset: 0x0000C8E0
|
||||
public bool PublicOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.keypairGenerated && (this.d == null || this.n == null);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000073 RID: 115
|
||||
// (get) Token: 0x06000246 RID: 582 RVA: 0x0000E71C File Offset: 0x0000C91C
|
||||
public override string SignatureAlgorithm
|
||||
{
|
||||
get
|
||||
{
|
||||
return "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000247 RID: 583 RVA: 0x0000E724 File Offset: 0x0000C924
|
||||
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: 0x06000248 RID: 584 RVA: 0x0000E8E0 File Offset: 0x0000CAE0
|
||||
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: 0x06000249 RID: 585 RVA: 0x0000E94C File Offset: 0x0000CB4C
|
||||
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: 0x0600024A RID: 586 RVA: 0x0000EAFC File Offset: 0x0000CCFC
|
||||
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: 0x0600024B RID: 587 RVA: 0x0000ED84 File Offset: 0x0000CF84
|
||||
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: 0x0600024C RID: 588 RVA: 0x0000EEC4 File Offset: 0x0000D0C4
|
||||
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: 0x17000074 RID: 116
|
||||
// (get) Token: 0x0600024D RID: 589 RVA: 0x0000F18C File Offset: 0x0000D38C
|
||||
// (set) Token: 0x0600024E RID: 590 RVA: 0x0000F194 File Offset: 0x0000D394
|
||||
public bool UseKeyBlinding
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.keyBlinding;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.keyBlinding = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000075 RID: 117
|
||||
// (get) Token: 0x0600024F RID: 591 RVA: 0x0000F1A0 File Offset: 0x0000D3A0
|
||||
public bool IsCrtPossible
|
||||
{
|
||||
get
|
||||
{
|
||||
return !this.keypairGenerated || this.isCRTpossible;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000250 RID: 592 RVA: 0x0000F1B8 File Offset: 0x0000D3B8
|
||||
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: 0x040000F2 RID: 242
|
||||
private const int defaultKeySize = 1024;
|
||||
|
||||
// Token: 0x040000F3 RID: 243
|
||||
private bool isCRTpossible;
|
||||
|
||||
// Token: 0x040000F4 RID: 244
|
||||
private bool keyBlinding = true;
|
||||
|
||||
// Token: 0x040000F5 RID: 245
|
||||
private bool keypairGenerated;
|
||||
|
||||
// Token: 0x040000F6 RID: 246
|
||||
private bool m_disposed;
|
||||
|
||||
// Token: 0x040000F7 RID: 247
|
||||
private BigInteger d;
|
||||
|
||||
// Token: 0x040000F8 RID: 248
|
||||
private BigInteger p;
|
||||
|
||||
// Token: 0x040000F9 RID: 249
|
||||
private BigInteger q;
|
||||
|
||||
// Token: 0x040000FA RID: 250
|
||||
private BigInteger dp;
|
||||
|
||||
// Token: 0x040000FB RID: 251
|
||||
private BigInteger dq;
|
||||
|
||||
// Token: 0x040000FC RID: 252
|
||||
private BigInteger qInv;
|
||||
|
||||
// Token: 0x040000FD RID: 253
|
||||
private BigInteger n;
|
||||
|
||||
// Token: 0x040000FE RID: 254
|
||||
private BigInteger e;
|
||||
|
||||
// Token: 0x020000C8 RID: 200
|
||||
// (Invoke) Token: 0x06000705 RID: 1797
|
||||
public delegate void KeyGeneratedEventHandler(object sender, EventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000038 RID: 56
|
||||
public abstract class SHA224 : HashAlgorithm
|
||||
{
|
||||
// Token: 0x06000253 RID: 595 RVA: 0x0000F220 File Offset: 0x0000D420
|
||||
public SHA224()
|
||||
{
|
||||
this.HashSizeValue = 224;
|
||||
}
|
||||
|
||||
// Token: 0x06000254 RID: 596 RVA: 0x0000F234 File Offset: 0x0000D434
|
||||
public new static SHA224 Create()
|
||||
{
|
||||
return SHA224.Create("SHA224");
|
||||
}
|
||||
|
||||
// Token: 0x06000255 RID: 597 RVA: 0x0000F240 File Offset: 0x0000D440
|
||||
public new static SHA224 Create(string hashName)
|
||||
{
|
||||
object obj = CryptoConfig.CreateFromName(hashName);
|
||||
if (obj == null)
|
||||
{
|
||||
obj = new SHA224Managed();
|
||||
}
|
||||
return (SHA224)obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000039 RID: 57
|
||||
public class SHA224Managed : SHA224
|
||||
{
|
||||
// Token: 0x06000256 RID: 598 RVA: 0x0000F268 File Offset: 0x0000D468
|
||||
public SHA224Managed()
|
||||
{
|
||||
this._H = new uint[8];
|
||||
this._ProcessingBuffer = new byte[64];
|
||||
this.Initialize();
|
||||
}
|
||||
|
||||
// Token: 0x06000257 RID: 599 RVA: 0x0000F290 File Offset: 0x0000D490
|
||||
private uint Ch(uint u, uint v, uint w)
|
||||
{
|
||||
return (u & v) ^ (~u & w);
|
||||
}
|
||||
|
||||
// Token: 0x06000258 RID: 600 RVA: 0x0000F29C File Offset: 0x0000D49C
|
||||
private uint Maj(uint u, uint v, uint w)
|
||||
{
|
||||
return (u & v) ^ (u & w) ^ (v & w);
|
||||
}
|
||||
|
||||
// Token: 0x06000259 RID: 601 RVA: 0x0000F2AC File Offset: 0x0000D4AC
|
||||
private uint Ro0(uint x)
|
||||
{
|
||||
return ((x >> 7) | (x << 25)) ^ ((x >> 18) | (x << 14)) ^ (x >> 3);
|
||||
}
|
||||
|
||||
// Token: 0x0600025A RID: 602 RVA: 0x0000F2C4 File Offset: 0x0000D4C4
|
||||
private uint Ro1(uint x)
|
||||
{
|
||||
return ((x >> 17) | (x << 15)) ^ ((x >> 19) | (x << 13)) ^ (x >> 10);
|
||||
}
|
||||
|
||||
// Token: 0x0600025B RID: 603 RVA: 0x0000F2E0 File Offset: 0x0000D4E0
|
||||
private uint Sig0(uint x)
|
||||
{
|
||||
return ((x >> 2) | (x << 30)) ^ ((x >> 13) | (x << 19)) ^ ((x >> 22) | (x << 10));
|
||||
}
|
||||
|
||||
// Token: 0x0600025C RID: 604 RVA: 0x0000F300 File Offset: 0x0000D500
|
||||
private uint Sig1(uint x)
|
||||
{
|
||||
return ((x >> 6) | (x << 26)) ^ ((x >> 11) | (x << 21)) ^ ((x >> 25) | (x << 7));
|
||||
}
|
||||
|
||||
// Token: 0x0600025D RID: 605 RVA: 0x0000F320 File Offset: 0x0000D520
|
||||
protected override void HashCore(byte[] rgb, int start, int size)
|
||||
{
|
||||
this.State = 1;
|
||||
if (this._ProcessingBufferCount != 0)
|
||||
{
|
||||
if (size < 64 - this._ProcessingBufferCount)
|
||||
{
|
||||
Buffer.BlockCopy(rgb, start, this._ProcessingBuffer, this._ProcessingBufferCount, size);
|
||||
this._ProcessingBufferCount += size;
|
||||
return;
|
||||
}
|
||||
int i = 64 - this._ProcessingBufferCount;
|
||||
Buffer.BlockCopy(rgb, start, this._ProcessingBuffer, this._ProcessingBufferCount, i);
|
||||
this.ProcessBlock(this._ProcessingBuffer, 0);
|
||||
this._ProcessingBufferCount = 0;
|
||||
start += i;
|
||||
size -= i;
|
||||
}
|
||||
for (int i = 0; i < size - size % 64; i += 64)
|
||||
{
|
||||
this.ProcessBlock(rgb, start + i);
|
||||
}
|
||||
if (size % 64 != 0)
|
||||
{
|
||||
Buffer.BlockCopy(rgb, size - size % 64 + start, this._ProcessingBuffer, 0, size % 64);
|
||||
this._ProcessingBufferCount = size % 64;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600025E RID: 606 RVA: 0x0000F3FC File Offset: 0x0000D5FC
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
byte[] array = new byte[28];
|
||||
this.ProcessFinalBlock(this._ProcessingBuffer, 0, this._ProcessingBufferCount);
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
array[i * 4 + j] = (byte)(this._H[i] >> 24 - j * 8);
|
||||
}
|
||||
}
|
||||
this.State = 0;
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x0600025F RID: 607 RVA: 0x0000F46C File Offset: 0x0000D66C
|
||||
public override void Initialize()
|
||||
{
|
||||
this.count = 0UL;
|
||||
this._ProcessingBufferCount = 0;
|
||||
this._H[0] = 3238371032U;
|
||||
this._H[1] = 914150663U;
|
||||
this._H[2] = 812702999U;
|
||||
this._H[3] = 4144912697U;
|
||||
this._H[4] = 4290775857U;
|
||||
this._H[5] = 1750603025U;
|
||||
this._H[6] = 1694076839U;
|
||||
this._H[7] = 3204075428U;
|
||||
}
|
||||
|
||||
// Token: 0x06000260 RID: 608 RVA: 0x0000F4F0 File Offset: 0x0000D6F0
|
||||
private void ProcessBlock(byte[] inputBuffer, int inputOffset)
|
||||
{
|
||||
this.count += 64UL;
|
||||
uint[] array = new uint[64];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
array[i] = (uint)(((int)inputBuffer[inputOffset + 4 * i] << 24) | ((int)inputBuffer[inputOffset + 4 * i + 1] << 16) | ((int)inputBuffer[inputOffset + 4 * i + 2] << 8) | (int)inputBuffer[inputOffset + 4 * i + 3]);
|
||||
}
|
||||
for (int i = 16; i < 64; i++)
|
||||
{
|
||||
array[i] = this.Ro1(array[i - 2]) + array[i - 7] + this.Ro0(array[i - 15]) + array[i - 16];
|
||||
}
|
||||
uint num = this._H[0];
|
||||
uint num2 = this._H[1];
|
||||
uint num3 = this._H[2];
|
||||
uint num4 = this._H[3];
|
||||
uint num5 = this._H[4];
|
||||
uint num6 = this._H[5];
|
||||
uint num7 = this._H[6];
|
||||
uint num8 = this._H[7];
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
uint num9 = num8 + this.Sig1(num5) + this.Ch(num5, num6, num7) + SHAConstants.K1[i] + array[i];
|
||||
uint num10 = this.Sig0(num) + this.Maj(num, num2, num3);
|
||||
num8 = num7;
|
||||
num7 = num6;
|
||||
num6 = num5;
|
||||
num5 = num4 + num9;
|
||||
num4 = num3;
|
||||
num3 = num2;
|
||||
num2 = num;
|
||||
num = num9 + num10;
|
||||
}
|
||||
this._H[0] += num;
|
||||
this._H[1] += num2;
|
||||
this._H[2] += num3;
|
||||
this._H[3] += num4;
|
||||
this._H[4] += num5;
|
||||
this._H[5] += num6;
|
||||
this._H[6] += num7;
|
||||
this._H[7] += num8;
|
||||
}
|
||||
|
||||
// Token: 0x06000261 RID: 609 RVA: 0x0000F6F8 File Offset: 0x0000D8F8
|
||||
private void ProcessFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
|
||||
{
|
||||
ulong num = this.count + (ulong)((long)inputCount);
|
||||
int num2 = 56 - (int)(num % 64UL);
|
||||
if (num2 < 1)
|
||||
{
|
||||
num2 += 64;
|
||||
}
|
||||
byte[] array = new byte[inputCount + num2 + 8];
|
||||
for (int i = 0; i < inputCount; i++)
|
||||
{
|
||||
array[i] = inputBuffer[i + inputOffset];
|
||||
}
|
||||
array[inputCount] = 128;
|
||||
for (int j = inputCount + 1; j < inputCount + num2; j++)
|
||||
{
|
||||
array[j] = 0;
|
||||
}
|
||||
ulong num3 = num << 3;
|
||||
this.AddLength(num3, array, inputCount + num2);
|
||||
this.ProcessBlock(array, 0);
|
||||
if (inputCount + num2 + 8 == 128)
|
||||
{
|
||||
this.ProcessBlock(array, 64);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000262 RID: 610 RVA: 0x0000F7A4 File Offset: 0x0000D9A4
|
||||
internal void AddLength(ulong length, byte[] buffer, int position)
|
||||
{
|
||||
buffer[position++] = (byte)(length >> 56);
|
||||
buffer[position++] = (byte)(length >> 48);
|
||||
buffer[position++] = (byte)(length >> 40);
|
||||
buffer[position++] = (byte)(length >> 32);
|
||||
buffer[position++] = (byte)(length >> 24);
|
||||
buffer[position++] = (byte)(length >> 16);
|
||||
buffer[position++] = (byte)(length >> 8);
|
||||
buffer[position] = (byte)length;
|
||||
}
|
||||
|
||||
// Token: 0x04000101 RID: 257
|
||||
private const int BLOCK_SIZE_BYTES = 64;
|
||||
|
||||
// Token: 0x04000102 RID: 258
|
||||
private uint[] _H;
|
||||
|
||||
// Token: 0x04000103 RID: 259
|
||||
private ulong count;
|
||||
|
||||
// Token: 0x04000104 RID: 260
|
||||
private byte[] _ProcessingBuffer;
|
||||
|
||||
// Token: 0x04000105 RID: 261
|
||||
private int _ProcessingBufferCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x02000037 RID: 55
|
||||
internal sealed class SHAConstants
|
||||
{
|
||||
// Token: 0x06000251 RID: 593 RVA: 0x0000F1FC File Offset: 0x0000D3FC
|
||||
private SHAConstants()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x04000100 RID: 256
|
||||
public static readonly uint[] K1 = new uint[]
|
||||
{
|
||||
1116352408U, 1899447441U, 3049323471U, 3921009573U, 961987163U, 1508970993U, 2453635748U, 2870763221U, 3624381080U, 310598401U,
|
||||
607225278U, 1426881987U, 1925078388U, 2162078206U, 2614888103U, 3248222580U, 3835390401U, 4022224774U, 264347078U, 604807628U,
|
||||
770255983U, 1249150122U, 1555081692U, 1996064986U, 2554220882U, 2821834349U, 2952996808U, 3210313671U, 3336571891U, 3584528711U,
|
||||
113926993U, 338241895U, 666307205U, 773529912U, 1294757372U, 1396182291U, 1695183700U, 1986661051U, 2177026350U, 2456956037U,
|
||||
2730485921U, 2820302411U, 3259730800U, 3345764771U, 3516065817U, 3600352804U, 4094571909U, 275423344U, 430227734U, 506948616U,
|
||||
659060556U, 883997877U, 958139571U, 1322822218U, 1537002063U, 1747873779U, 1955562222U, 2024104815U, 2227730452U, 2361852424U,
|
||||
2428436474U, 2756734187U, 3204031479U, 3329325298U
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,556 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Mono.Security.Cryptography
|
||||
{
|
||||
// Token: 0x0200003A RID: 58
|
||||
internal abstract class SymmetricTransform : IDisposable, ICryptoTransform
|
||||
{
|
||||
// Token: 0x06000263 RID: 611 RVA: 0x0000F810 File Offset: 0x0000DA10
|
||||
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: 0x06000264 RID: 612 RVA: 0x0000F93C File Offset: 0x0000DB3C
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Token: 0x06000265 RID: 613 RVA: 0x0000F94C File Offset: 0x0000DB4C
|
||||
~SymmetricTransform()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
// Token: 0x06000266 RID: 614 RVA: 0x0000F988 File Offset: 0x0000DB88
|
||||
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: 0x17000076 RID: 118
|
||||
// (get) Token: 0x06000267 RID: 615 RVA: 0x0000F9E0 File Offset: 0x0000DBE0
|
||||
public virtual bool CanTransformMultipleBlocks
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000077 RID: 119
|
||||
// (get) Token: 0x06000268 RID: 616 RVA: 0x0000F9E4 File Offset: 0x0000DBE4
|
||||
public virtual bool CanReuseTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000078 RID: 120
|
||||
// (get) Token: 0x06000269 RID: 617 RVA: 0x0000F9E8 File Offset: 0x0000DBE8
|
||||
public virtual int InputBlockSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.BlockSizeByte;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000079 RID: 121
|
||||
// (get) Token: 0x0600026A RID: 618 RVA: 0x0000F9F0 File Offset: 0x0000DBF0
|
||||
public virtual int OutputBlockSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.BlockSizeByte;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600026B RID: 619 RVA: 0x0000F9F8 File Offset: 0x0000DBF8
|
||||
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: 0x0600026C RID: 620
|
||||
protected abstract void ECB(byte[] input, byte[] output);
|
||||
|
||||
// Token: 0x0600026D RID: 621 RVA: 0x0000FA98 File Offset: 0x0000DC98
|
||||
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: 0x0600026E RID: 622 RVA: 0x0000FB64 File Offset: 0x0000DD64
|
||||
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: 0x0600026F RID: 623 RVA: 0x0000FCC4 File Offset: 0x0000DEC4
|
||||
protected virtual void OFB(byte[] input, byte[] output)
|
||||
{
|
||||
throw new CryptographicException("OFB isn't supported by the framework");
|
||||
}
|
||||
|
||||
// Token: 0x06000270 RID: 624 RVA: 0x0000FCD0 File Offset: 0x0000DED0
|
||||
protected virtual void CTS(byte[] input, byte[] output)
|
||||
{
|
||||
throw new CryptographicException("CTS isn't supported by the framework");
|
||||
}
|
||||
|
||||
// Token: 0x06000271 RID: 625 RVA: 0x0000FCDC File Offset: 0x0000DEDC
|
||||
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: 0x06000272 RID: 626 RVA: 0x0000FD48 File Offset: 0x0000DF48
|
||||
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: 0x1700007A RID: 122
|
||||
// (get) Token: 0x06000273 RID: 627 RVA: 0x0000FE70 File Offset: 0x0000E070
|
||||
private bool KeepLastBlock
|
||||
{
|
||||
get
|
||||
{
|
||||
return !this.encrypt && this.algo.Padding != PaddingMode.None && this.algo.Padding != PaddingMode.Zeros;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000274 RID: 628 RVA: 0x0000FEB0 File Offset: 0x0000E0B0
|
||||
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: 0x06000275 RID: 629 RVA: 0x0000FFE4 File Offset: 0x0000E1E4
|
||||
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: 0x06000276 RID: 630 RVA: 0x00010024 File Offset: 0x0000E224
|
||||
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: 0x06000277 RID: 631 RVA: 0x00010094 File Offset: 0x0000E294
|
||||
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: 0x06000278 RID: 632 RVA: 0x000102A0 File Offset: 0x0000E4A0
|
||||
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: 0x06000279 RID: 633 RVA: 0x000104DC File Offset: 0x0000E6DC
|
||||
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: 0x04000106 RID: 262
|
||||
protected SymmetricAlgorithm algo;
|
||||
|
||||
// Token: 0x04000107 RID: 263
|
||||
protected bool encrypt;
|
||||
|
||||
// Token: 0x04000108 RID: 264
|
||||
private int BlockSizeByte;
|
||||
|
||||
// Token: 0x04000109 RID: 265
|
||||
private byte[] temp;
|
||||
|
||||
// Token: 0x0400010A RID: 266
|
||||
private byte[] temp2;
|
||||
|
||||
// Token: 0x0400010B RID: 267
|
||||
private byte[] workBuff;
|
||||
|
||||
// Token: 0x0400010C RID: 268
|
||||
private byte[] workout;
|
||||
|
||||
// Token: 0x0400010D RID: 269
|
||||
private int FeedBackByte;
|
||||
|
||||
// Token: 0x0400010E RID: 270
|
||||
private int FeedBackIter;
|
||||
|
||||
// Token: 0x0400010F RID: 271
|
||||
private bool m_disposed;
|
||||
|
||||
// Token: 0x04000110 RID: 272
|
||||
private bool lastBlock;
|
||||
|
||||
// Token: 0x04000111 RID: 273
|
||||
private RandomNumberGenerator _rng;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user