使用 ASP.NET Core 计算 SHA1 [英] Computing SHA1 with ASP.NET Core
问题描述
我有一个 ASP.NET 5 RC1(即将成为 ASP.NET Core)Web 应用程序项目.
I've got a ASP.NET 5 RC1 (soon to be ASP.NET Core) Web Application project.
它需要计算 SHA1 哈希值.
It needs to compute SHA1 hashes.
各种 SHA1
子类都可用并在 DNX 4.5.1 下构建,但在 DNX Core 5.0 下似乎没有任何可用的实现.
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.
我是否必须添加引用才能引入该代码,还是它根本不适用于 .NET Core?
Do I have to add a reference to bring that code in, or is it simply not available for .NET Core yet?
根据这篇文章:
.NET Core 由一组名为CoreFX"的库和一个名为CoreCLR"的小型优化运行时组成.
.NET Core consists of a set of libraries, called "CoreFX", and a small, optimized runtime, called "CoreCLR".
果然,在CoreFX repo中,没有SHA1
的子类:
Sure enough, in the CoreFX repo, there are no subclasses of SHA1
:
但是在 CoreCLR 中,子类如您所料,在 mscorlib 中:
However in CoreCLR the subclasses are there as you'd expect, within mscorlib:
为什么coreclr 和corefx 有重叠?此 mscorlib 代码是否不适用于 .NET Core 项目?
Why is there overlap between coreclr and corefx? Is this mscorlib code not available for .NET Core projects?
系统的描述NuGet 上的 .Security.Crytpography.Algorithms
包 说:
为加密算法提供基本类型,包括散列、加密和签名操作.
Provides base types for cryptographic algorithms, including hashing, encryption, and signing operations.
是否有另一个包含实际算法而不仅仅是基类的包?这是尚未移植的东西吗?有什么地方可以像 Mono 那样查看 API 的状态和路线图吗?
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?
推荐答案
添加 System.Security.Cryptography.Algorithms
nuget 包.
Add the System.Security.Cryptography.Algorithms
nuget package.
然后
var sha1 = System.Security.Cryptography.SHA1.Create();
var hash = sha1.ComputeHash(myByteArray)
这篇关于使用 ASP.NET Core 计算 SHA1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!