本文整理汇总了C#中System.Numerics.BigInteger.ToCleanByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.ToCleanByteArray方法的具体用法?C# BigInteger.ToCleanByteArray怎么用?C# BigInteger.ToCleanByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.ToCleanByteArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleRealmLogonChallenge
void HandleRealmLogonChallenge()
{
ServerAuthChallenge challenge = new ServerAuthChallenge(new BinaryReader(connection.GetStream()));
switch (challenge.error)
{
case AuthResult.SUCCESS:
{
Game.UI.LogLine("Received logon challenge", LogLevel.Debug);
BigInteger N, A, B, a, u, x, S, salt, unk1, g, k;
k = new BigInteger(3);
#region Receive and initialize
B = challenge.B.ToBigInteger(); // server public key
g = challenge.g.ToBigInteger();
N = challenge.N.ToBigInteger(); // modulus
salt = challenge.salt.ToBigInteger();
unk1 = challenge.unk3.ToBigInteger();
Game.UI.LogLine("---====== Received from server: ======---", LogLevel.Debug);
Game.UI.LogLine(string.Format("B={0}", B.ToCleanByteArray().ToHexString()), LogLevel.Debug);
Game.UI.LogLine(string.Format("N={0}", N.ToCleanByteArray().ToHexString()), LogLevel.Debug);
Game.UI.LogLine(string.Format("salt={0}", challenge.salt.ToHexString()), LogLevel.Debug);
#endregion
#region Hash password
x = HashAlgorithm.SHA1.Hash(challenge.salt, PasswordHash).ToBigInteger();
Game.UI.LogLine("---====== shared password hash ======---", LogLevel.Debug);
Game.UI.LogLine(string.Format("g={0}", g.ToCleanByteArray().ToHexString()), LogLevel.Debug);
Game.UI.LogLine(string.Format("x={0}", x.ToCleanByteArray().ToHexString()), LogLevel.Debug);
Game.UI.LogLine(string.Format("N={0}", N.ToCleanByteArray().ToHexString()), LogLevel.Debug);
#endregion
#region Create random key pair
var rand = System.Security.Cryptography.RandomNumberGenerator.Create();
do
{
byte[] randBytes = new byte[19];
rand.GetBytes(randBytes);
a = randBytes.ToBigInteger();
A = g.ModPow(a, N);
} while (A.ModPow(1, N) == 0);
Game.UI.LogLine("---====== Send data to server: ======---", LogLevel.Debug);
Game.UI.LogLine(string.Format("A={0}", A.ToCleanByteArray().ToHexString()), LogLevel.Debug);
#endregion
#region Compute session key
u = HashAlgorithm.SHA1.Hash(A.ToCleanByteArray(), B.ToCleanByteArray()).ToBigInteger();
// compute session key
// TODO: session key computation fails for some reason
// all variables match exactly to the server side, but
// S is different
S = (B - k * g.ModPow(x, N)).ModPow(a + u * x, N);
byte[] keyHash;
byte[] sData = S.ToCleanByteArray();
byte[] keyData = new byte[40];
byte[] temp = new byte[16];
// take every even indices byte, hash, store in even indices
for (int i = 0; i < 16; ++i)
temp[i] = sData[i * 2];
keyHash = HashAlgorithm.SHA1.Hash(temp);
for (int i = 0; i < 20; ++i)
keyData[i * 2] = keyHash[i];
// do the same for odd indices
for (int i = 0; i < 16; ++i)
temp[i] = sData[i * 2 + 1];
keyHash = HashAlgorithm.SHA1.Hash(temp);
for (int i = 0; i < 20; ++i)
keyData[i * 2 + 1] = keyHash[i];
Key = keyData.ToBigInteger();
Game.UI.LogLine("---====== Compute session key ======---", LogLevel.Debug);
Game.UI.LogLine(string.Format("u={0}", u.ToCleanByteArray().ToHexString()), LogLevel.Debug);
Game.UI.LogLine(string.Format("S={0}", S.ToCleanByteArray().ToHexString()), LogLevel.Debug);
Game.UI.LogLine(string.Format("K={0}", Key.ToCleanByteArray().ToHexString()), LogLevel.Debug);
#endregion
#region Generate crypto proof
// XOR the hashes of N and g together
byte[] gNHash = new byte[20];
//.........这里部分代码省略.........