Added challenge generation function to generate cryptographic strength challenges.

0.1-prestable
Adam Frisby 2007-04-27 02:16:57 +00:00
parent 379552b0f9
commit 3659e64274
1 changed files with 19 additions and 0 deletions

View File

@ -72,9 +72,28 @@ namespace OpenSim.Framework
return currentHash;
}
/// <summary>
/// Generates a new challenge string to be issued to a foreign host. Challenges are 1024-bit messages generated using the Crytographic Random Number Generator.
/// </summary>
/// <returns>A 128-character hexadecimal string containing the challenge.</returns>
public static string GenerateChallenge()
{
RNGCryptoServiceProvider RNG = new RNGCryptoServiceProvider();
byte[] bytes = new byte[64];
RNG.GetBytes(bytes);
StringBuilder sb = new StringBuilder(bytes.Length * 2);
foreach (byte b in bytes)
{
sb.AppendFormat("{0:x2}", b);
}
return sb.ToString();
}
/// <summary>
/// Helper function, merges two byte arrays
/// </summary>
/// <remarks>Sourced from MSDN Forum</remarks>
/// <param name="a">A</param>
/// <param name="b">B</param>
/// <returns>C</returns>