aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs52
1 files changed, 32 insertions, 20 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index d1d8736..96292ff 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -409,19 +409,25 @@ namespace OpenSim.Framework
409 /// </summary> 409 /// </summary>
410 /// <param name="data"></param> 410 /// <param name="data"></param>
411 /// <returns></returns> 411 /// <returns></returns>
412
412 public static string Md5Hash(string data) 413 public static string Md5Hash(string data)
413 { 414 {
414 byte[] dataMd5 = ComputeMD5Hash(data); 415 return Md5Hash(data, Encoding.Default);
416 }
417
418 public static string Md5Hash(string data, Encoding encoding)
419 {
420 byte[] dataMd5 = ComputeMD5Hash(data, encoding);
415 StringBuilder sb = new StringBuilder(); 421 StringBuilder sb = new StringBuilder();
416 for (int i = 0; i < dataMd5.Length; i++) 422 for (int i = 0; i < dataMd5.Length; i++)
417 sb.AppendFormat("{0:x2}", dataMd5[i]); 423 sb.AppendFormat("{0:x2}", dataMd5[i]);
418 return sb.ToString(); 424 return sb.ToString();
419 } 425 }
420 426
421 private static byte[] ComputeMD5Hash(string data) 427 private static byte[] ComputeMD5Hash(string data, Encoding encoding)
422 { 428 {
423 MD5 md5 = MD5.Create(); 429 MD5 md5 = MD5.Create();
424 return md5.ComputeHash(Encoding.Default.GetBytes(data)); 430 return md5.ComputeHash(encoding.GetBytes(data));
425 } 431 }
426 432
427 /// <summary> 433 /// <summary>
@@ -429,16 +435,22 @@ namespace OpenSim.Framework
429 /// </summary> 435 /// </summary>
430 /// <param name="data"></param> 436 /// <param name="data"></param>
431 /// <returns></returns> 437 /// <returns></returns>
438
432 public static string SHA1Hash(string data) 439 public static string SHA1Hash(string data)
433 { 440 {
434 byte[] hash = ComputeSHA1Hash(data); 441 return SHA1Hash(data, Encoding.Default);
442 }
443
444 public static string SHA1Hash(string data, Encoding encoding)
445 {
446 byte[] hash = ComputeSHA1Hash(data, encoding);
435 return BitConverter.ToString(hash).Replace("-", String.Empty); 447 return BitConverter.ToString(hash).Replace("-", String.Empty);
436 } 448 }
437 449
438 private static byte[] ComputeSHA1Hash(string src) 450 private static byte[] ComputeSHA1Hash(string src, Encoding encoding)
439 { 451 {
440 SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider(); 452 SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();
441 return SHA1.ComputeHash(Encoding.Default.GetBytes(src)); 453 return SHA1.ComputeHash(encoding.GetBytes(src));
442 } 454 }
443 455
444 public static int fast_distance2d(int x, int y) 456 public static int fast_distance2d(int x, int y)
@@ -1016,19 +1028,19 @@ namespace OpenSim.Framework
1016 { 1028 {
1017 string os = String.Empty; 1029 string os = String.Empty;
1018 1030
1019 if (Environment.OSVersion.Platform != PlatformID.Unix) 1031// if (Environment.OSVersion.Platform != PlatformID.Unix)
1020 { 1032// {
1021 os = Environment.OSVersion.ToString(); 1033// os = Environment.OSVersion.ToString();
1022 } 1034// }
1023 else 1035// else
1024 { 1036// {
1025 os = ReadEtcIssue(); 1037// os = ReadEtcIssue();
1026 } 1038// }
1027 1039//
1028 if (os.Length > 45) 1040// if (os.Length > 45)
1029 { 1041// {
1030 os = os.Substring(0, 45); 1042// os = os.Substring(0, 45);
1031 } 1043// }
1032 1044
1033 return os; 1045 return os;
1034 } 1046 }
@@ -1161,7 +1173,7 @@ namespace OpenSim.Framework
1161 1173
1162 public static Guid GetHashGuid(string data, string salt) 1174 public static Guid GetHashGuid(string data, string salt)
1163 { 1175 {
1164 byte[] hash = ComputeMD5Hash(data + salt); 1176 byte[] hash = ComputeMD5Hash(data + salt, Encoding.Default);
1165 1177
1166 //string s = BitConverter.ToString(hash); 1178 //string s = BitConverter.ToString(hash);
1167 1179