Added challenge generation function to generate cryptographic strength challenges.
parent
379552b0f9
commit
3659e64274
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue