Revert my previous SHA1 commit in favour of a better implementation

avinationmerge
Tom 2011-01-26 12:54:12 -08:00
parent 63dcd44e87
commit 04c62c4959
2 changed files with 10 additions and 6 deletions

View File

@ -435,16 +435,22 @@ namespace OpenSim.Framework
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <returns></returns> /// <returns></returns>
public static string SHA1Hash(string data) public static string SHA1Hash(string data)
{ {
byte[] hash = ComputeSHA1Hash(data); return SHA1Hash(data, Encoding.Default);
}
public static string SHA1Hash(string data, Encoding encoding)
{
byte[] hash = ComputeSHA1Hash(data, encoding);
return BitConverter.ToString(hash).Replace("-", String.Empty); return BitConverter.ToString(hash).Replace("-", String.Empty);
} }
private static byte[] ComputeSHA1Hash(string src) private static byte[] ComputeSHA1Hash(string src, Encoding encoding)
{ {
SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider(); SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();
return SHA1.ComputeHash(Encoding.Default.GetBytes(src)); return SHA1.ComputeHash(encoding.GetBytes(src));
} }
public static int fast_distance2d(int x, int y) public static int fast_distance2d(int x, int y)

View File

@ -32,7 +32,6 @@ using System.Diagnostics; //for [DebuggerNonUserCode]
using System.Runtime.Remoting.Lifetime; using System.Runtime.Remoting.Lifetime;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Security.Cryptography;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Nini.Config; using Nini.Config;
using log4net; using log4net;
@ -6945,8 +6944,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_String llSHA1String(string src) public LSL_String llSHA1String(string src)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider(); return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
return BitConverter.ToString(SHA1.ComputeHash(Encoding.UTF8.GetBytes(src))).Replace("-", String.Empty).ToLower();
} }
protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist) protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)