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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user