1

C#, Hashing, encoding, encryption

Class C# 1 revisions 162 a year ago a year ago
/* 3way#7547 on Discord
 * ####################
 * NOTES:
 * These only take a single string as input
 * decoding/hashing functions are not provided
 */

public public class bigBadHashing
{
    public string SHA1(string input)
    { /* SHA1 hashing thing */
        byte[] hash;
        using (var sha1 = new 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 SHA256(string input)
    { /* SHA256 hashing thing */
        byte[] hash;
        using (var sha256 = new SHA256CryptoServiceProvider())
        {
            hash = sha256.ComputeHash(Encoding.Unicode.GetBytes(input));
        }
        var sb = new StringBuilder();
        foreach (byte b in hash) sb.AppendFormat("{0:x2}", b);
        return sb.ToString();
    }

    public string SHA384(string input)
    { /* SHA384 hashing thing */
        byte[] hash;
        using (var sha384 = new SHA384CryptoServiceProvider())
        {
            hash = sha384.ComputeHash(Encoding.Unicode.GetBytes(input));
        }
        var sb = new StringBuilder();
        foreach (byte b in hash) sb.AppendFormat("{0:x2}", b);
        return sb.ToString();
    }

    public string SHA512(string input)
    { /* SHA512 hashing thing */
        byte[] hash;
        using (var sha512 = new SHA512CryptoServiceProvider())
        {
            hash = sha512.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 hashing thing */
        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();
    }
}

Some simple hashing/encoding functions for C#