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 aaa2724..366a38f 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)
@@ -1023,19 +1035,19 @@ namespace OpenSim.Framework
1023 { 1035 {
1024 string os = String.Empty; 1036 string os = String.Empty;
1025 1037
1026 if (Environment.OSVersion.Platform != PlatformID.Unix) 1038// if (Environment.OSVersion.Platform != PlatformID.Unix)
1027 { 1039// {
1028 os = Environment.OSVersion.ToString(); 1040// os = Environment.OSVersion.ToString();
1029 } 1041// }
1030 else 1042// else
1031 { 1043// {
1032 os = ReadEtcIssue(); 1044// os = ReadEtcIssue();
1033 } 1045// }
1034 1046//
1035 if (os.Length > 45) 1047// if (os.Length > 45)
1036 { 1048// {
1037 os = os.Substring(0, 45); 1049// os = os.Substring(0, 45);
1038 } 1050// }
1039 1051
1040 return os; 1052 return os;
1041 } 1053 }
@@ -1168,7 +1180,7 @@ namespace OpenSim.Framework
1168 1180
1169 public static Guid GetHashGuid(string data, string salt) 1181 public static Guid GetHashGuid(string data, string salt)
1170 { 1182 {
1171 byte[] hash = ComputeMD5Hash(data + salt); 1183 byte[] hash = ComputeMD5Hash(data + salt, Encoding.Default);
1172 1184
1173 //string s = BitConverter.ToString(hash); 1185 //string s = BitConverter.ToString(hash);
1174 1186