diff options
author | lbsa71 | 2009-04-01 06:11:51 +0000 |
---|---|---|
committer | lbsa71 | 2009-04-01 06:11:51 +0000 |
commit | 0266c344fb425e1338f988f542fc532e9b47aa1f (patch) | |
tree | 3fc692aa2ee65e20f60a6dfaadb7fc33c3379db5 /OpenSim/Framework/Util.cs | |
parent | * Removes some hard-coded magic numbers relating to RegionSize. We now use Co... (diff) | |
download | opensim-SC-0266c344fb425e1338f988f542fc532e9b47aa1f.zip opensim-SC-0266c344fb425e1338f988f542fc532e9b47aa1f.tar.gz opensim-SC-0266c344fb425e1338f988f542fc532e9b47aa1f.tar.bz2 opensim-SC-0266c344fb425e1338f988f542fc532e9b47aa1f.tar.xz |
* Added NUnit tested utility function GetHashGuid() for future use.
* Did some aligning refactoring of the MD5 and SHA-1 functions.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Util.cs | 37 |
1 files changed, 30 insertions, 7 deletions
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 | |||
338 | /// <summary> | 338 | /// <summary> |
339 | /// Return an md5 hash of the given string | 339 | /// Return an md5 hash of the given string |
340 | /// </summary> | 340 | /// </summary> |
341 | /// <param name="pass"></param> | 341 | /// <param name="data"></param> |
342 | /// <returns></returns> | 342 | /// <returns></returns> |
343 | public static string Md5Hash(string pass) | 343 | public static string Md5Hash(string data) |
344 | { | 344 | { |
345 | MD5 md5 = MD5.Create(); | 345 | byte[] dataMd5 = ComputeMD5Hash(data); |
346 | byte[] dataMd5 = md5.ComputeHash(Encoding.Default.GetBytes(pass)); | ||
347 | StringBuilder sb = new StringBuilder(); | 346 | StringBuilder sb = new StringBuilder(); |
348 | for (int i = 0; i < dataMd5.Length; i++) | 347 | for (int i = 0; i < dataMd5.Length; i++) |
349 | sb.AppendFormat("{0:x2}", dataMd5[i]); | 348 | sb.AppendFormat("{0:x2}", dataMd5[i]); |
350 | return sb.ToString(); | 349 | return sb.ToString(); |
351 | } | 350 | } |
352 | 351 | ||
352 | private static byte[] ComputeMD5Hash(string data) | ||
353 | { | ||
354 | MD5 md5 = MD5.Create(); | ||
355 | return md5.ComputeHash(Encoding.Default.GetBytes(data)); | ||
356 | } | ||
357 | |||
353 | /// <summary> | 358 | /// <summary> |
354 | /// Return an SHA1 hash of the given string | 359 | /// Return an SHA1 hash of the given string |
355 | /// </summary> | 360 | /// </summary> |
356 | /// <param name="src"></param> | 361 | /// <param name="data"></param> |
357 | /// <returns></returns> | 362 | /// <returns></returns> |
358 | public static string SHA1Hash(string src) | 363 | public static string SHA1Hash(string data) |
364 | { | ||
365 | byte[] hash = ComputeSHA1Hash(data); | ||
366 | return BitConverter.ToString(hash).Replace("-", String.Empty); | ||
367 | } | ||
368 | |||
369 | private static byte[] ComputeSHA1Hash(string src) | ||
359 | { | 370 | { |
360 | SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider(); | 371 | SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider(); |
361 | return BitConverter.ToString(SHA1.ComputeHash(Encoding.Default.GetBytes(src))).Replace("-", String.Empty); | 372 | return SHA1.ComputeHash(Encoding.Default.GetBytes(src)); |
362 | } | 373 | } |
363 | 374 | ||
375 | |||
364 | public static int fast_distance2d(int x, int y) | 376 | public static int fast_distance2d(int x, int y) |
365 | { | 377 | { |
366 | x = Math.Abs(x); | 378 | x = Math.Abs(x); |
@@ -1007,5 +1019,16 @@ namespace OpenSim.Framework | |||
1007 | string result = new String(decoded_char); | 1019 | string result = new String(decoded_char); |
1008 | return result; | 1020 | return result; |
1009 | } | 1021 | } |
1022 | |||
1023 | public static Guid GetHashGuid(string data, string salt) | ||
1024 | { | ||
1025 | byte[] hash = ComputeMD5Hash( data + salt ); | ||
1026 | |||
1027 | string s = BitConverter.ToString(hash); | ||
1028 | |||
1029 | Guid guid = new Guid( hash ); | ||
1030 | |||
1031 | return guid; | ||
1032 | } | ||
1010 | } | 1033 | } |
1011 | } | 1034 | } |