.net - 使用 ASP.NET Core 计算 SHA1

标签 .net asp.net-core sha1 .net-core

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

它需要计算 SHA1 哈希值。

各种 SHA1子类在 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 repo中,没有SHA1的子类:

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

然而,在 CoreCLR 中,子类如您所料,在 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)

关于.net - 使用 ASP.NET Core 计算 SHA1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35363358/

相关文章:

c# - WPF动画不流畅

c# - 如何将日志记录添加到 Blazor 服务器端组件?

c# - 找不到任何已安装的.NET Core SDK

.net - 何时在 F# 中引发 nullArg

c# - Blazor RenderFragment 到字符串

.Net Core 主机进程 Windows 2016 IIS 中的高 CPU 使用率在 Asp.Net Core 2.2 应用程序中

c++ - 计算大于 400mb 的大文件的 sha-1 或 CRC32 校验和

.net - Microsoft 的 SHA-1 弃用是否会影响基于 Microsoft 技术的 Web 服务客户端

具有反向哈希自定义查询的 MySQL 复制

.net - System.Timers.Timer 与 System.Threading.Timer