Compute SHA1 of byte array in UWP

HashAlgorithmProvider is provided in Windows.Security.Cryptography.Core, which allows developer to compute SHA1 values of byte arrays.

First at all, we need to make reference to Windows.Security.Cryptography.Core

1
using Windows.Security.Cryptography.Core;

Then, create a reusable cryptography hash with the opened the SHA1 algorithm and assign it to a variable.

1
var hash = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha1).CreateHash();

Get the buffer of the byte array needs to be computed and append it to the hash you created just now.

1
hash.Append(bytes.AsBuffer());

Now, the hash contains the SHA1 data of the specified array. If you want, you can convert the hash into byte array using the following line of codes:

1
hash.GetValueAndReset().ToArray();