From 63dcd44e8727a4e264feaf2d981c70bbfa209811 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 26 Jan 2011 12:47:43 -0800 Subject: Provide an SL compatible llMD5String function across all platforms --- OpenSim/Framework/Util.cs | 14 ++++++++++---- .../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index cef756c..9227708 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -409,19 +409,25 @@ namespace OpenSim.Framework /// /// /// + 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)); } /// @@ -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); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 1ccf76e..45af13a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -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) -- cgit v1.1