public static byte[] ToHmac(this byte[] data, byte[] key, HashAlgorithm algorithm = HashAlgorithm.Sha512) { switch (algorithm) { case HashAlgorithm.Md5: using (System.Security.Cryptography.HMACMD5 hmac = new(key)) { return(hmac.ComputeHash(data)); } case HashAlgorithm.Sha1: using (System.Security.Cryptography.HMACSHA1 hmac = new(key)) { return(hmac.ComputeHash(data)); } case HashAlgorithm.Sha256: using (System.Security.Cryptography.HMACSHA256 hmac = new(key)) { return(hmac.ComputeHash(data)); } case HashAlgorithm.Sha384: using (System.Security.Cryptography.HMACSHA384 hmac = new(key)) { return(hmac.ComputeHash(data)); } case HashAlgorithm.Sha512: using (System.Security.Cryptography.HMACSHA512 hmac = new(key)) { return(hmac.ComputeHash(data)); } default: throw new NotImplementedException(algorithm.ToString()); } }
public static byte[] ToHash(this byte[] data, HashAlgorithm algorithm = HashAlgorithm.Sha512) { switch (algorithm) { case HashAlgorithm.Md5: return(MD5.Create().ComputeHash(data)); case HashAlgorithm.Sha1: return(SHA1.Create().ComputeHash(data)); case HashAlgorithm.Sha256: return(SHA256.Create().ComputeHash(data)); case HashAlgorithm.Sha384: return(SHA384.Create().ComputeHash(data)); case HashAlgorithm.Sha512: return(SHA512.Create().ComputeHash(data)); default: throw new NotImplementedException(algorithm.ToString()); } }
public static string ToHash(this string data, IEncoder encoder, HashAlgorithm algorithm = HashAlgorithm.Sha512) { return(encoder.Encode(ToHash(data.ToByteArray(), algorithm))); }
public static byte[] ToHash(this string data, HashAlgorithm algorithm = HashAlgorithm.Sha512) { byte[] dataBytes = data.ToByteArray(); return(ToHash(dataBytes, algorithm)); }
public static HmacResult ToHmac(string data, string key, IEncoder encoder, HashAlgorithm algorithm = HashAlgorithm.Sha512) { return(ToHmac(data.ToByteArray(), encoder.Decode(key), encoder, algorithm)); }
public static HmacResult ToHmac(this string data, IEncoder encoder, uint keySize = HmacKeySize, HashAlgorithm algorithm = HashAlgorithm.Sha512) { return(ToHmac(data.ToByteArray(), RandomManager.Next((int)keySize), encoder, algorithm)); }
public static HmacResult ToHmac(this byte[] data, byte[] key, IEncoder encoder, HashAlgorithm algorithm = HashAlgorithm.Sha512) { return(new HmacResult( hash: encoder.Encode(ToHmac(data, key, algorithm)), key: encoder.Encode(key), algorithm: algorithm, encoder: encoder )); }