As other responders said, hashing is processor related activity, so it does not have Async methods that you can call. You can, however, make your hash method asynchronous asynchronously read a block of files by block , and then hash the bytes that you read from the file. Hashing will be done synchronously, but reading will be asynchronous, and therefore your whole method will be asynchronous.
Here is a sample code to achieve the goal I just described.
public static async Threading.Tasks.Task<string> GetHashAsync<T>(this Stream stream) where T : HashAlgorithm, new() { StringBuilder sb; using (var algo = new T()) { var buffer = new byte[8192]; int read;
Function can be called as such
using (var stream = System.IO.File.OpenRead(@"C:\path\to\file.txt")) string sha256 = await stream.GetHashAsync<SHA256CryptoServiceProvider>();
Of course, you could also call the method with other hashing algorithms such as SHA1CryptoServiceProvider or SHA512CryptoServiceProvider as a type parameter.
Similarly, with some changes, you can also get it for hashing a string, as this is specific to your case.
source share