使用 ASP.NET 核心计算 SHA1

Computing SHA1 with ASP.NET Core

我有一个 ASP.NET 5 RC1(即将成为 ASP.NET 核心)Web 应用程序项目。

它需要计算 SHA1 哈希值。

各种 SHA1 sub类 可用并在 DNX 4.5.1 下构建,但在 DNX Core 5.0 下似乎没有任何可用的实现。

我是否必须添加引用才能引入该代码,或者它是否还不适用于 .NET Core?

根据this article

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

果然,在 CoreFX 回购中,SHA1:

没有子类

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

但是在 CoreCLR 中,sub类 就如您所料,在 mscorlib 中:

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

为什么coreclr和corefx有重叠?此 mscorlib 代码不适用于 .NET Core 项目吗?

System.Security.Crytpography.Algorithms package on NuGet 的描述说:

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

是否有另一个包包含实际算法而不仅仅是基础 类?这是还没有移植的东西吗?有没有什么地方可以像 Mono 那样查看 API 的状态和路线图?

添加 System.Security.Cryptography.Algorithms nuget 包。

然后

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

var hash = sha1.ComputeHash(myByteArray)