From 2d61ae8f62d02d30fe051318a404412b452fba36 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 28 Nov 2014 17:14:52 +0000 Subject: [PATCH] added function for calculating hash (MD5 format) --- Saviour Backup System/tools.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Saviour Backup System/tools.cs b/Saviour Backup System/tools.cs index 1e91c1c..875c7f2 100644 --- a/Saviour Backup System/tools.cs +++ b/Saviour Backup System/tools.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Security.Cryptography; namespace Saviour_Backup_System { @@ -16,5 +17,21 @@ namespace Saviour_Backup_System } return value; } + + public static string hash(string input) + { + // step 1, calculate MD5 hash from input + MD5 md5 = MD5.Create(); + byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input); + byte[] hash = md5.ComputeHash(inputBytes); + + // step 2, convert byte array to hex string + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < hash.Length; i++) + { + sb.Append(hash[i].ToString("X2")); + } + return sb.ToString(); + } } }