public static async Task <string> GenerateChecksumAsync(HashingAlgoTypes hashingAlgo, string filename) { using (var hasher = HashAlgorithm.Create(hashingAlgo.ToString())) { using (FileStream stream = File.OpenRead(filename)) { byte[] hash = hasher.ComputeHash(stream); return(BitConverter.ToString(hash).Replace("-", "")); } } }
//True is good public static async Task <bool> VerifyChecksumAsync(HashingAlgoTypes hashingAlgo, string checksum, string filename) { //Hasher is disposeble using (var hasher = HashAlgorithm.Create(hashingAlgo.ToString())) { using (FileStream stream = File.OpenRead(filename)) { string hash = BitConverter.ToString(hasher.ComputeHash(stream)).Replace("-", ""); if (hash == checksum) { return(true); } else { return(false); } } } }