使用ASP.NET Core计算SHA1 [英] Computing SHA1 with ASP.NET Core

查看:489
本文介绍了使用ASP.NET Core计算SHA1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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存储库中,没有 SHA1 :

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

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

但是在CoreCLR中,子类在mscorlib中如您所愿:

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

https://github.com/dotnet/coreclr/tree/43b39a73cbf832ec13ec29ed356cb75834e7a8d7/Security/ / a>

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

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

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

System.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆