// MD5 public static byte[] CalculateHash(hashType hashType, byte[] input) { using HashAlgorithm hash = hashType switch { hashType.MD5 => MD5.Create(), hashType.SHA1 => SHA1.Create(), hashType.SHA256 => SHA256.Create(), hashType.SHA384 => SHA384.Create(), hashType.SHA512 => SHA512.Create(), _ => throw new ArgumentException("Invalid hash type"), }; return(hash !.ComputeHash(input)); }
public static string CalculateHashString(string input, hashType HashType = hashType.MD5) { if (HashType == hashType.MD5) { return(CalculateMD5HashString(input)); } if (HashType == hashType.SHA2_256) { return(CalculateSHA2_256HashString(input)); } return(null); }
public static string CalculateHashHex(hashType hashType, string input) => CalculateHashHex(hashType, Encoding.UTF8.GetBytes(input));
public static string CalculateHashHex(hashType hashType, byte[] input) => StringUtils.BinaryToHex(CalculateHash(hashType, input));