HashBy

public static byte[] HashBy<T>(this byte[] x) where T : HashAlgorithm {
			HashAlgorithm algo;
			try {
				algo = typeof(T)
					.GetMethod("Create", BindingFlags.Public | BindingFlags.Static, null, new Type[] { }, null)
						.Invoke(null, null) as HashAlgorithm;
			}
			catch {
				algo = Activator.CreateInstance<T>();
			}
			return algo.ComputeHash(x);
		}
Example:
Console.WriteLine("Hello World!".ToByteArray().HashBy<MD5>());

Description

Implict hashing

Details

Double click on the code to select all.

 

;