Verify Hex Hash, Base64 Hash, Byte Hash : Hash « Security « C# / C Sharp






Verify Hex Hash, Base64 Hash, Byte Hash

   


using System;
using System.Text;

class MainClass {
    public static bool VerifyHexHash(byte[] hash, string oldHashString) {
        StringBuilder newHashString = new StringBuilder(hash.Length);

        foreach (byte b in hash) {
            newHashString.AppendFormat("{0:X2}", b);
        }

        return (oldHashString == newHashString.ToString());
    }

    private static bool VerifyB64Hash(byte[] hash, string oldHashString) {
        string newHashString = Convert.ToBase64String(hash);
        return (oldHashString == newHashString);
    }
    private static bool VerifyByteHash(byte[] hash, byte[] oldHash) {
        if (hash == null || oldHash == null || hash.Length != oldHash.Length)
            return false;

        for (int count = 0; count < hash.Length; count++) {
            if (hash[count] != oldHash[count]) return false;
        }

        return true;
    }
}

   
    
  








Related examples in the same category

1.Generic Hash
2.Get Public Key Hash with HttpClientCertificate
3.Get Public Key Hash with SHA256
4.Get Public Key Hash for a string
5.Hash As Password
6.Generate Hash
7.Get Hash for password
8.Generates a hash code of the input string
9.Hash Data
10.Hash Password
11.Get SHA256 Hash
12.Create Password Hash