本文整理汇总了C#中User.GenServerKey方法的典型用法代码示例。如果您正苦于以下问题:C# User.GenServerKey方法的具体用法?C# User.GenServerKey怎么用?C# User.GenServerKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.GenServerKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SecureHandshake_SingleUser
private static void SecureHandshake_SingleUser()
{
MazeErrorCode clientError = MazeErrorCode.Error;
MazeErrorCode serverError = MazeErrorCode.Error;
int multiplier = 100;
//create users
User temp_user = new User();
Console.WriteLine("[Server] Creating user table...");
//Add real data here if you want to test this out
temp_user.Username = "TestUser";
temp_user.Password = "SomeStrongPasswordHere";
temp_user.PublicKey = GetRandomBytes(128 * multiplier); //File.ReadAllBytes("./Data/PublicKey1.dat"));
temp_user.PrivateKeys.Add(GetRandomBytes(128 * multiplier)); //File.ReadAllBytes("./Data/PrivateKey1.dat"));
temp_user.PrivateKeys.Add(GetRandomBytes(128 * multiplier)); //(File.ReadAllBytes("./Data/PrivateKey2.dat"));
temp_user.GenServerKey();
ClientMaze client = new ClientMaze(new System.Drawing.Size(128, 128), 1, 5);
ServerMaze server = new ServerMaze(new System.Drawing.Size(128, 128), 1, 5);
server.onFindKeyInDatabase += server_onFindKeyInDatabase;
Server_Users = new List<User>();
Server_Users.Add(temp_user);
while (true)
{
Console.WriteLine(".............................................................");
Stopwatch sw = Stopwatch.StartNew();
byte[] ClientResponseData = new byte[0];
byte[] ServerResponseData = new byte[0];
//1. Send server the bytecode
byte[] byteCode = client.GetByteCode();
Console.WriteLine("[Client] Sending ByteCode to server");
//2. Server receives the ByteCode
serverError = server.onReceiveData(byteCode, ref ServerResponseData);
if (serverError == MazeErrorCode.Success)
{
Console.WriteLine("[Server] ByteCode is correct, continue on with handshake");
}
else
{
Console.WriteLine("[Server] ByteCode is not correct, disconnecting...");
}
//in this example we will simply keep this simple, so no additional encryption(s) will be used here except the one that is being used by the handshake it self
Console.WriteLine("[Client] Setting login data... username:" + temp_user.Username);
client.SetLoginData(temp_user.Username, temp_user.Password, temp_user.PrivateKeys, temp_user.PublicKey);
Console.WriteLine("[Client] Calculating the key");
BigInteger mazeKey = client.SetMazeKey();
Console.WriteLine("[Client] Encrypting the public key & sending public key");
byte[] encryptedPublicKey = client.GetEncryptedPublicKey();
Console.WriteLine("[Server] Received encrypted public key");
serverError = server.onReceiveData(encryptedPublicKey, ref ServerResponseData);
if (serverError != MazeErrorCode.Success)
{
Console.WriteLine("[Server] Encrypted Public Key was not found in database or something else went wrong");
continue;//Process.GetCurrentProcess().WaitForExit();
}
Console.WriteLine("[Server] Sending back response to client len:" + ServerResponseData.Length);
Console.WriteLine("[Client] Received response from server... len:" + ServerResponseData.Length + ", sending response back...");
clientError = client.onReceiveData(ServerResponseData, ref ClientResponseData);
if (clientError != MazeErrorCode.Success && clientError != MazeErrorCode.Finished)
{
Console.WriteLine("[Client] Incorrect response from server");
continue;//Process.GetCurrentProcess().WaitForExit();
}
Console.WriteLine("[Server] Received response from client len:" + ServerResponseData.Length);
serverError = server.onReceiveData(ClientResponseData, ref ServerResponseData);
if (serverError != MazeErrorCode.Success && serverError != MazeErrorCode.Finished)
{
Console.WriteLine("[Server] Incorrect response from client");
continue;//Process.GetCurrentProcess().WaitForExit();
}
Console.WriteLine("[Client] Applied the key to the encryption");
Console.WriteLine("[Server] Applied the key to the encryption");
Console.WriteLine("[Client-Key] " + BitConverter.ToString(client.wopEx.Key).Substring(0, 50) + "....");
Console.WriteLine("[Client-Salt] " + BitConverter.ToString(client.wopEx.Salt).Substring(0, 50) + "....");
Console.WriteLine("[Server-Key] " + BitConverter.ToString(server.wopEx.Key).Substring(0, 50) + "....");
Console.WriteLine("[Server-Salt] " + BitConverter.ToString(server.wopEx.Salt).Substring(0, 50));
sw.Stop();
Console.WriteLine("Done... Authenticated without sending login data, completed in " + sw.Elapsed);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Re-Calculating the private keys");
int keyCount = temp_user.PrivateKeys.Count;
//.........这里部分代码省略.........
示例2: KeepTestingHandshake
private static void KeepTestingHandshake()
{
MazeErrorCode clientError = MazeErrorCode.Error;
MazeErrorCode serverError = MazeErrorCode.Error;
int multiplier = 100;
while (true)
{
Server_Users = new List<User>();
//create users
User temp_user = new User();
temp_user.Username = ASCIIEncoding.ASCII.GetString(GetRandomBytes(20));
temp_user.Password = ASCIIEncoding.ASCII.GetString(GetRandomBytes(20));
temp_user.PublicKey = GetRandomBytes(128 * multiplier); //File.ReadAllBytes("./Data/PublicKey1.dat"));
//for (int i = 0; i < temp_user.PublicKey.Length; i++)
// temp_user.PublicKey[i] = (byte)(i % 100);
temp_user.PrivateKeys.Add(GetRandomBytes(128 * multiplier)); //File.ReadAllBytes("./Data/PrivateKey1.dat"));
temp_user.PrivateKeys.Add(GetRandomBytes(128 * multiplier)); //(File.ReadAllBytes("./Data/PrivateKey2.dat"));
Console.WriteLine("[Server] Creating user table...");
temp_user.GenServerKey();
Server_Users.Add(temp_user);
Console.WriteLine(".............................................................");
foreach (User User in Server_Users)
{
Stopwatch sw = Stopwatch.StartNew();
ClientMaze client = new ClientMaze(new System.Drawing.Size(128, 128), 1, 5);
ServerMaze server = new ServerMaze(new System.Drawing.Size(128, 128), 1, 5);
server.onFindKeyInDatabase += server_onFindKeyInDatabase;
byte[] ClientResponseData = new byte[0];
byte[] ServerResponseData = new byte[0];
//1. Send server the bytecode
byte[] byteCode = client.GetByteCode();
Console.WriteLine("[Client] Sending ByteCode to server");
//2. Server receives the ByteCode
serverError = server.onReceiveData(byteCode, ref ServerResponseData);
if (serverError == MazeErrorCode.Success)
{
Console.WriteLine("[Server] ByteCode is correct, continue on with handshake");
}
else
{
Console.WriteLine("[Server] ByteCode is not correct, disconnecting...");
}
//in this example we will simply keep this simple, so no additional encryption(s) will be used here except the one that is being used by the handshake it self
Console.WriteLine("[Client] Setting login data... username:" + User.Username);
client.SetLoginData(User.Username, User.Password, User.PrivateKeys, User.PublicKey);
Console.WriteLine("[Client] Calculating the key");
BigInteger mazeKey = client.SetMazeKey();
Console.WriteLine("[Client] Encrypting the public key & sending public key");
byte[] encryptedPublicKey = client.GetEncryptedPublicKey();
Console.WriteLine("[Server] Received encrypted public key");
serverError = server.onReceiveData(encryptedPublicKey, ref ServerResponseData);
if (serverError != MazeErrorCode.Success)
{
Console.WriteLine("[Server] Encrypted Public Key was not found in database or something else went wrong");
continue;//Process.GetCurrentProcess().WaitForExit();
}
Console.WriteLine("[Server] Sending back response to client len:" + ServerResponseData.Length);
Console.WriteLine("[Client] Received response from server... len:" + ServerResponseData.Length + ", sending response back...");
clientError = client.onReceiveData(ServerResponseData, ref ClientResponseData);
if (clientError != MazeErrorCode.Success && clientError != MazeErrorCode.Finished)
{
Console.WriteLine("[Client] Incorrect response from server");
continue;//Process.GetCurrentProcess().WaitForExit();
}
Console.WriteLine("[Server] Received response from client len:" + ServerResponseData.Length);
serverError = server.onReceiveData(ClientResponseData, ref ServerResponseData);
if (serverError != MazeErrorCode.Success && serverError != MazeErrorCode.Finished)
{
Console.WriteLine("[Server] Incorrect response from client");
continue;//Process.GetCurrentProcess().WaitForExit();
}
Console.WriteLine("[Client] Applied the key to the encryption");
Console.WriteLine("[Server] Applied the key to the encryption");
Console.WriteLine("[Client-Key] " + BitConverter.ToString(client.wopEx.Key).Substring(0, 50) + "....");
Console.WriteLine("[Client-Salt] " + BitConverter.ToString(client.wopEx.Salt).Substring(0, 50) + "....");
Console.WriteLine("[Server-Key] " + BitConverter.ToString(server.wopEx.Key).Substring(0, 50) + "....");
Console.WriteLine("[Server-Salt] " + BitConverter.ToString(server.wopEx.Salt).Substring(0, 50));
sw.Stop();
Console.WriteLine("Done... Authenticated without sending login data, completed in " + sw.Elapsed);
}
}
}
示例3: Test_MazeAuthentication
public void Test_MazeAuthentication()
{
MazeErrorCode clientError = MazeErrorCode.Error;
MazeErrorCode serverError = MazeErrorCode.Error;
List<User> Server_Users = new List<User>();
//create users
User temp_user = new User();
temp_user.Username = "";
temp_user.Password = "";
temp_user.PublicKey = File.ReadAllBytes("./Data/PublicKey1.dat");
temp_user.PrivateKeys.Add(File.ReadAllBytes("./Data/PrivateKey1.dat"));
temp_user.PrivateKeys.Add(File.ReadAllBytes("./Data/PrivateKey2.dat"));
temp_user.GenServerKey();
Server_Users.Add(temp_user);
Console.WriteLine(".............................................................");
foreach (User User in Server_Users)
{
Stopwatch sw = Stopwatch.StartNew();
ClientMaze client = new ClientMaze(new System.Drawing.Size(512, 512), 10, 30);
ServerMaze server = new ServerMaze(new System.Drawing.Size(512, 512), 10, 30);
server.onFindKeyInDatabase += (string EncryptedHash, ref byte[] Key, ref byte[] Salt, ref byte[] PublicKey, ref string Username) =>
{
foreach (User user in Server_Users)
{
if (user.EncryptedHash == EncryptedHash)
{
Key = user.ServerHandshake.MazeKey.getBytes();
Salt = user.ServerHandshake.PrivateSalt.getBytes();
PublicKey = user.PublicKey;
Username = user.Username;
return true;
}
}
return false;
};
byte[] ClientResponseData = new byte[0];
byte[] ServerResponseData = new byte[0];
//1. Send server the bytecode
byte[] byteCode = client.GetByteCode();
//2. Server receives the ByteCode
serverError = server.onReceiveData(byteCode, ref ServerResponseData);
if (serverError != MazeErrorCode.Success)
{
throw new Exception("[Server] ByteCode is not correct, disconnecting...");
}
//in this example we will simply keep this simple, so no additional encryption(s) will be used here except the one that is being used by the handshake it self
client.SetLoginData(User.Username, User.Password, User.PrivateKeys, User.PublicKey);
BigInteger mazeKey = client.SetMazeKey();
byte[] encryptedPublicKey = client.GetEncryptedPublicKey();
serverError = server.onReceiveData(encryptedPublicKey, ref ServerResponseData);
if (serverError != MazeErrorCode.Success)
{
throw new Exception("[Server] Encrypted Public Key was not found in database or something else went wrong");
}
clientError = client.onReceiveData(ServerResponseData, ref ClientResponseData);
if (clientError != MazeErrorCode.Success && clientError != MazeErrorCode.Finished)
{
throw new Exception("[Client] Incorrect response from server");
}
serverError = server.onReceiveData(ClientResponseData, ref ServerResponseData);
if (serverError != MazeErrorCode.Success && serverError != MazeErrorCode.Finished)
{
throw new Exception("[Server] Incorrect response from client");
}
}
}