diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 2253652838..b3399e57c3 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -38,6 +38,7 @@ using System.IO.Compression;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
@@ -1136,6 +1137,61 @@ namespace OpenSim.Framework
///
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static char LowNibbleToHexByteCharLowcaps(byte b)
+ {
+ b &= 0x0f;
+ return (char)(b > 9 ? b + 0x57 : b + '0');
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static char HighNibbleToHexByteCharLowcaps(byte b)
+ {
+ b >>= 4;
+ return (char)(b > 9 ? b + 0x57 : b + '0');
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static char LowNibbleToHexByteCharHighcaps(byte b)
+ {
+ b &= 0x0f;
+ return (char)(b > 9 ? b + 0x57 : b + '0');
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static char HighNibbleToHexByteCharHighcaps(byte b)
+ {
+ b >>= 4;
+ return (char)(b > 9 ? b + 0x57 : b + '0');
+ }
+
+ public static string bytesToHexString(byte[] bytes, bool lowerCaps)
+ {
+ if(bytes == null || bytes.Length == 0)
+ return string.Empty;
+
+ char[] chars = new char[2* bytes.Length];
+ if(lowerCaps)
+ {
+ for (int i = 0, j = 0; i < bytes.Length; ++i)
+ {
+ byte b = bytes[i];
+ chars[j++] = HighNibbleToHexByteCharLowcaps(b);
+ chars[j++] = LowNibbleToHexByteCharLowcaps(b);
+ }
+ }
+ else
+ {
+ for (int i = 0, j = 0; i < bytes.Length; ++i)
+ {
+ byte b = bytes[i];
+ chars[j++] = HighNibbleToHexByteCharHighcaps(b);
+ chars[j++] = LowNibbleToHexByteCharHighcaps(b);
+ }
+ }
+ return new string(chars);
+ }
+
public static string SHA1Hash(string data, Encoding enc)
{
return SHA1Hash(enc.GetBytes(data));
@@ -1154,7 +1210,7 @@ namespace OpenSim.Framework
public static string SHA1Hash(byte[] data)
{
byte[] hash = ComputeSHA1Hash(data);
- return BitConverter.ToString(hash).Replace("-", String.Empty);
+ return bytesToHexString(hash, false);
}
private static byte[] ComputeSHA1Hash(byte[] src)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 1b24735685..1321b0b663 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -2612,16 +2612,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// Create a SHA256
using (SHA256 sha256Hash = SHA256.Create())
{
- // ComputeHash - returns byte array
+ // ComputeHash - returns byte array
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
-
- // Convert byte array to a string
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < bytes.Length; i++)
- {
- builder.Append(bytes[i].ToString("x2"));
- }
- return builder.ToString();
+ return Util.bytesToHexString(bytes, true);
}
}