ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
Home
Upgrade
Credits
Help
Search
Awards
Achievements
 3608

[C#] SHA1 & MD5 Hashing

by IcyJake - 11-16-2017 - 05:03 AM
#1
I got bored the other day and I don't visit this forum that much and I'm gonna try to change that, so to start that off, I'm 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. Cool
Reply
#2
code looks good danke
Reply
#3
adz8cika1 Wrote:code looks good danke

Thanks a lot man!!
Reply
#4
Code is a bit messy but thanks for the share :)
:pepe:
Reply
#5
(03-08-2018 - 07:52 PM)FTPService Wrote: Code is a bit messy but thanks for the share :)

How is it messy? Also, you're welcome.
Reply
#6
(03-11-2018 - 06:41 PM)IcyJake Wrote:
(03-08-2018 - 07:52 PM)FTPService Wrote: Code is a bit messy but thanks for the share :)

How is it messy? Also, you're welcome.

Well they both use 2 entirely different methods to get the hex string for starters. And the 2nd method doesn't dispose of the MD5 provider.
Reply
#7
You should use "var" always you can, like when you did "string pass" or "string result". Not big deal but it improve your code
Reply
#8
looks great dude keep up the work
Reply

Users browsing: 3 Guest(s)