public static string GetHashSum(string item, HashSumType type) { HashAlgorithm hash = CreateHashService(type); byte[] result = hash.ComputeHash(Encoding.ASCII.GetBytes(item)); return BitConverter.ToString(result).ToLower().Replace("-", ""); }
private static HashAlgorithm CreateHashService(HashSumType type) { switch (type) { case HashSumType.MD5: return new MD5CryptoServiceProvider(); case HashSumType.SHA1: return new SHA1CryptoServiceProvider(); case HashSumType.SHA256: return new SHA256CryptoServiceProvider(); case HashSumType.SHA512: return new SHA512CryptoServiceProvider(); } return new MD5CryptoServiceProvider(); }