Provide an SL compatible llMD5String function across all platforms

avinationmerge
Tom 2011-01-26 12:47:43 -08:00
parent 4d3696d658
commit 63dcd44e87
2 changed files with 11 additions and 5 deletions

View File

@ -409,19 +409,25 @@ namespace OpenSim.Framework
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string Md5Hash(string data)
{
byte[] dataMd5 = ComputeMD5Hash(data);
return Md5Hash(data, Encoding.Default);
}
public static string Md5Hash(string data, Encoding encoding)
{
byte[] dataMd5 = ComputeMD5Hash(data, encoding);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < dataMd5.Length; i++)
sb.AppendFormat("{0:x2}", dataMd5[i]);
return sb.ToString();
}
private static byte[] ComputeMD5Hash(string data)
private static byte[] ComputeMD5Hash(string data, Encoding encoding)
{
MD5 md5 = MD5.Create();
return md5.ComputeHash(Encoding.Default.GetBytes(data));
return md5.ComputeHash(encoding.GetBytes(data));
}
/// <summary>
@ -1161,7 +1167,7 @@ namespace OpenSim.Framework
public static Guid GetHashGuid(string data, string salt)
{
byte[] hash = ComputeMD5Hash(data + salt);
byte[] hash = ComputeMD5Hash(data + salt, Encoding.Default);
//string s = BitConverter.ToString(hash);

View File

@ -6939,7 +6939,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_String llMD5String(string src, int nonce)
{
m_host.AddScriptLPS(1);
return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()));
return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
}
public LSL_String llSHA1String(string src)