Added challenge generation function to generate cryptographic strength challenges.
parent
379552b0f9
commit
3659e64274
|
@ -72,9 +72,28 @@ namespace OpenSim.Framework
|
||||||
return currentHash;
|
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>
|
/// <summary>
|
||||||
/// Helper function, merges two byte arrays
|
/// Helper function, merges two byte arrays
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>Sourced from MSDN Forum</remarks>
|
||||||
/// <param name="a">A</param>
|
/// <param name="a">A</param>
|
||||||
/// <param name="b">B</param>
|
/// <param name="b">B</param>
|
||||||
/// <returns>C</returns>
|
/// <returns>C</returns>
|
||||||
|
|
Loading…
Reference in New Issue