From 0266c344fb425e1338f988f542fc532e9b47aa1f Mon Sep 17 00:00:00 2001
From: lbsa71
Date: Wed, 1 Apr 2009 06:11:51 +0000
Subject: * Added NUnit tested utility function GetHashGuid() for future use. *
Did some aligning refactoring of the MD5 and SHA-1 functions.
---
OpenSim/Framework/Util.cs | 37 ++++++++++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 7 deletions(-)
(limited to 'OpenSim/Framework/Util.cs')
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index cce2adb..a0cac96 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -338,29 +338,41 @@ namespace OpenSim.Framework
///
/// Return an md5 hash of the given string
///
- ///
+ ///
///
- public static string Md5Hash(string pass)
+ public static string Md5Hash(string data)
{
- MD5 md5 = MD5.Create();
- byte[] dataMd5 = md5.ComputeHash(Encoding.Default.GetBytes(pass));
+ byte[] dataMd5 = ComputeMD5Hash(data);
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)
+ {
+ MD5 md5 = MD5.Create();
+ return md5.ComputeHash(Encoding.Default.GetBytes(data));
+ }
+
///
/// Return an SHA1 hash of the given string
///
- ///
+ ///
///
- public static string SHA1Hash(string src)
+ public static string SHA1Hash(string data)
+ {
+ byte[] hash = ComputeSHA1Hash(data);
+ return BitConverter.ToString(hash).Replace("-", String.Empty);
+ }
+
+ private static byte[] ComputeSHA1Hash(string src)
{
SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();
- return BitConverter.ToString(SHA1.ComputeHash(Encoding.Default.GetBytes(src))).Replace("-", String.Empty);
+ return SHA1.ComputeHash(Encoding.Default.GetBytes(src));
}
+
public static int fast_distance2d(int x, int y)
{
x = Math.Abs(x);
@@ -1007,5 +1019,16 @@ namespace OpenSim.Framework
string result = new String(decoded_char);
return result;
}
+
+ public static Guid GetHashGuid(string data, string salt)
+ {
+ byte[] hash = ComputeMD5Hash( data + salt );
+
+ string s = BitConverter.ToString(hash);
+
+ Guid guid = new Guid( hash );
+
+ return guid;
+ }
}
}
--
cgit v1.1