Computing

[C#] [Release] SHA1 & MD5 Hashing

Submitted by IcyJake, , Thread ID: 71752

Thread Closed
28-01-2018, 03:38 AM
This post was last modified: 28-01-2018, 03:40 AM by IcyJake
#1
I got bored the other day and I ended up writing this code up, so I am going to share my class with you guys.

Code:
public class Hash
  {
    public string SHA1(string input)
    {
      byte[] hash;
      using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
      {
        hash = sha1.ComputeHash(Encoding.Unicode.GetBytes(input));
      }
      var sb = new StringBuilder();
      foreach (byte b in hash) sb.AppendFormat("{0:x2}", b);
      return sb.ToString();
    }
    public string MD5(string input)
    {
      MD5 md5 = new MD5CryptoServiceProvider();
      string pass = Console.ReadLine();
      byte[] checkSum = md5.ComputeHash(Encoding.Unicode.GetBytes(input));
      string result = BitConverter.ToString(checkSum).Replace("-", String.Empty);
      return result.ToLower();
    }
  }

If you guys encounter any problems, just apprise me about it and I will try to implement some kind of fix to any problems. Enjoy.

Users browsing this thread: 2 Guest(s)