Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computing SHA1 with ASP.NET Core

I've got a ASP.NET 5 RC1 (soon to be ASP.NET Core) Web Application project.

It needs to compute SHA1 hashes.

Various SHA1 subclasses are available and build under DNX 4.5.1, but there doesn't seem to be any available implementation under DNX Core 5.0.

Do I have to add a reference to bring that code in, or is it simply not available for .NET Core yet?

According to this article:

.NET Core consists of a set of libraries, called “CoreFX”, and a small, optimized runtime, called “CoreCLR”.

Sure enough, in the CoreFX repo, there are no subclasses of SHA1:

https://github.com/dotnet/corefx/tree/master/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography

However in CoreCLR the subclasses are there as you'd expect, within mscorlib:

https://github.com/dotnet/coreclr/tree/43b39a73cbf832ec13ec29ed356cb75834e7a8d7/src/mscorlib/src/System/Security/Cryptography

Why is there overlap between coreclr and corefx? Is this mscorlib code not available for .NET Core projects?

The description of the System.Security.Crytpography.Algorithms package on NuGet says:

Provides base types for cryptographic algorithms, including hashing, encryption, and signing operations.

Is there another package that includes actual algorithms and not just base classes? Is this something that simply hasn't been ported yet? Is there somewhere you can review the status of APIs and a roadmap, as Mono has?

like image 408
Drew Noakes Avatar asked Feb 12 '16 13:02

Drew Noakes


1 Answers

Add the System.Security.Cryptography.Algorithms nuget package.

Then

var sha1 = System.Security.Cryptography.SHA1.Create();

var hash = sha1.ComputeHash(myByteArray)
like image 199
blowdart Avatar answered Nov 09 '22 09:11

blowdart