Bladeren bron

added a new function string=osSHA256(string)

Signed-off-by: UbitUmarov <[email protected]>
Mike Higgins 3 jaren geleden
bovenliggende
commit
0da43a8ef5

+ 22 - 1
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs

@@ -47,6 +47,7 @@ using System.Runtime.Remoting.Lifetime;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading;
+using System.Security.Cryptography;
 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
 using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
 using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
@@ -2606,6 +2607,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
             return retval;
         }
 
+        public string osSHA256(string input)
+        {
+            // Create a SHA256   
+            using (SHA256 sha256Hash = SHA256.Create())  
+            {  
+                // 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();
+	    }
+        }
+
+
+
         /// <summary>
         /// Get the nickname of this grid, as set in the [GridInfo] config section.
         /// </summary>
@@ -5999,4 +6020,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
             return 1;
         }
     }
-}
+}

+ 1 - 0
OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs

@@ -283,6 +283,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
 
         string osAvatarName2Key(string firstname, string lastname);
         string osKey2Name(string id);
+	string osSHA256(string input);
 
         // Grid Info Functions
         string osGetGridNick();

+ 5 - 0
OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs

@@ -521,6 +521,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
             return m_OSSL_Functions.osKey2Name(id);
         }
 
+	public string osSHA256(string input)
+	{
+	    return m_OSSL_Functions.osSHA256(input);
+	}
+
         public string osGetGridNick()
         {
             return m_OSSL_Functions.osGetGridNick();