scripts
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using Photon.SocketServer.Numeric;
|
||||
|
||||
namespace Photon.SocketServer.Security
|
||||
{
|
||||
// Token: 0x02000004 RID: 4
|
||||
internal class DiffieHellmanCryptoProvider : ICryptoProvider, IDisposable
|
||||
{
|
||||
// Token: 0x06000009 RID: 9 RVA: 0x000020AF File Offset: 0x000002AF
|
||||
public DiffieHellmanCryptoProvider()
|
||||
{
|
||||
this.prime = new BigInteger(OakleyGroups.OakleyPrime768);
|
||||
this.secret = this.GenerateRandomSecret(160);
|
||||
this.publicKey = this.CalculatePublicKey();
|
||||
}
|
||||
|
||||
// Token: 0x0600000A RID: 10 RVA: 0x000020E8 File Offset: 0x000002E8
|
||||
public DiffieHellmanCryptoProvider(byte[] sharedSecretHash)
|
||||
{
|
||||
this.crypto = new RijndaelManaged();
|
||||
this.crypto.Key = sharedSecretHash;
|
||||
this.crypto.IV = new byte[16];
|
||||
this.crypto.Padding = PaddingMode.PKCS7;
|
||||
}
|
||||
|
||||
// Token: 0x17000003 RID: 3
|
||||
// (get) Token: 0x0600000B RID: 11 RVA: 0x00002138 File Offset: 0x00000338
|
||||
public bool IsInitialized
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.crypto != null;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000004 RID: 4
|
||||
// (get) Token: 0x0600000C RID: 12 RVA: 0x00002154 File Offset: 0x00000354
|
||||
public byte[] PublicKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.publicKey.GetBytes();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600000D RID: 13 RVA: 0x00002174 File Offset: 0x00000374
|
||||
public void DeriveSharedKey(byte[] otherPartyPublicKey)
|
||||
{
|
||||
BigInteger bigInteger = new BigInteger(otherPartyPublicKey);
|
||||
BigInteger bigInteger2 = this.CalculateSharedKey(bigInteger);
|
||||
this.sharedKey = bigInteger2.GetBytes();
|
||||
byte[] array;
|
||||
using (SHA256 sha = new SHA256Managed())
|
||||
{
|
||||
array = sha.ComputeHash(this.sharedKey);
|
||||
}
|
||||
this.crypto = new RijndaelManaged();
|
||||
this.crypto.Key = array;
|
||||
this.crypto.IV = new byte[16];
|
||||
this.crypto.Padding = PaddingMode.PKCS7;
|
||||
}
|
||||
|
||||
// Token: 0x0600000E RID: 14 RVA: 0x00002208 File Offset: 0x00000408
|
||||
public byte[] Encrypt(byte[] data)
|
||||
{
|
||||
return this.Encrypt(data, 0, data.Length);
|
||||
}
|
||||
|
||||
// Token: 0x0600000F RID: 15 RVA: 0x00002228 File Offset: 0x00000428
|
||||
public byte[] Encrypt(byte[] data, int offset, int count)
|
||||
{
|
||||
byte[] array;
|
||||
using (ICryptoTransform cryptoTransform = this.crypto.CreateEncryptor())
|
||||
{
|
||||
array = cryptoTransform.TransformFinalBlock(data, offset, count);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000010 RID: 16 RVA: 0x0000226C File Offset: 0x0000046C
|
||||
public byte[] Decrypt(byte[] data)
|
||||
{
|
||||
return this.Decrypt(data, 0, data.Length);
|
||||
}
|
||||
|
||||
// Token: 0x06000011 RID: 17 RVA: 0x0000228C File Offset: 0x0000048C
|
||||
public byte[] Decrypt(byte[] data, int offset, int count)
|
||||
{
|
||||
byte[] array;
|
||||
using (ICryptoTransform cryptoTransform = this.crypto.CreateDecryptor())
|
||||
{
|
||||
array = cryptoTransform.TransformFinalBlock(data, offset, count);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000012 RID: 18 RVA: 0x000022D0 File Offset: 0x000004D0
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Token: 0x06000013 RID: 19 RVA: 0x000022E4 File Offset: 0x000004E4
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
bool flag = !disposing;
|
||||
if (flag)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000014 RID: 20 RVA: 0x00002300 File Offset: 0x00000500
|
||||
private BigInteger CalculatePublicKey()
|
||||
{
|
||||
return DiffieHellmanCryptoProvider.primeRoot.ModPow(this.secret, this.prime);
|
||||
}
|
||||
|
||||
// Token: 0x06000015 RID: 21 RVA: 0x00002328 File Offset: 0x00000528
|
||||
private BigInteger CalculateSharedKey(BigInteger otherPartyPublicKey)
|
||||
{
|
||||
return otherPartyPublicKey.ModPow(this.secret, this.prime);
|
||||
}
|
||||
|
||||
// Token: 0x06000016 RID: 22 RVA: 0x0000234C File Offset: 0x0000054C
|
||||
private BigInteger GenerateRandomSecret(int secretLength)
|
||||
{
|
||||
BigInteger bigInteger;
|
||||
do
|
||||
{
|
||||
bigInteger = BigInteger.GenerateRandom(secretLength);
|
||||
}
|
||||
while (bigInteger >= this.prime - 1 || bigInteger == 0);
|
||||
return bigInteger;
|
||||
}
|
||||
|
||||
// Token: 0x04000005 RID: 5
|
||||
private static readonly BigInteger primeRoot = new BigInteger((long)OakleyGroups.Generator);
|
||||
|
||||
// Token: 0x04000006 RID: 6
|
||||
private readonly BigInteger prime;
|
||||
|
||||
// Token: 0x04000007 RID: 7
|
||||
private readonly BigInteger secret;
|
||||
|
||||
// Token: 0x04000008 RID: 8
|
||||
private readonly BigInteger publicKey;
|
||||
|
||||
// Token: 0x04000009 RID: 9
|
||||
private Rijndael crypto;
|
||||
|
||||
// Token: 0x0400000A RID: 10
|
||||
private byte[] sharedKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace Photon.SocketServer.Security
|
||||
{
|
||||
// Token: 0x02000003 RID: 3
|
||||
internal interface ICryptoProvider : IDisposable
|
||||
{
|
||||
// Token: 0x17000001 RID: 1
|
||||
// (get) Token: 0x06000002 RID: 2
|
||||
bool IsInitialized { get; }
|
||||
|
||||
// Token: 0x17000002 RID: 2
|
||||
// (get) Token: 0x06000003 RID: 3
|
||||
byte[] PublicKey { get; }
|
||||
|
||||
// Token: 0x06000004 RID: 4
|
||||
void DeriveSharedKey(byte[] otherPartyPublicKey);
|
||||
|
||||
// Token: 0x06000005 RID: 5
|
||||
byte[] Encrypt(byte[] data);
|
||||
|
||||
// Token: 0x06000006 RID: 6
|
||||
byte[] Encrypt(byte[] data, int offset, int count);
|
||||
|
||||
// Token: 0x06000007 RID: 7
|
||||
byte[] Decrypt(byte[] data);
|
||||
|
||||
// Token: 0x06000008 RID: 8
|
||||
byte[] Decrypt(byte[] data, int offset, int count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace Photon.SocketServer.Security
|
||||
{
|
||||
// Token: 0x02000002 RID: 2
|
||||
internal static class OakleyGroups
|
||||
{
|
||||
// Token: 0x04000001 RID: 1
|
||||
public static readonly int Generator = 22;
|
||||
|
||||
// Token: 0x04000002 RID: 2
|
||||
public static readonly byte[] OakleyPrime768 = 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: 0x04000003 RID: 3
|
||||
public static readonly byte[] OakleyPrime1024 = 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: 0x04000004 RID: 4
|
||||
public static readonly byte[] OakleyPrime1536 = 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
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user