我们在Asp.net 5 Core中使用哪种加密算法 [英] Which encryption algorithm do we use in Asp.net 5 Core

查看:115
本文介绍了我们在Asp.net 5 Core中使用哪种加密算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,当我将项目类型从Asp.net 5.0切换到Asp.net 5.0 Core时,几乎所有的加密算法都开始给我错误.这是因为它们都需要System.Security.Cryptography名称空间,而Core 5.0中不提供此名称空间.请参阅此处的一些代码示例.知道我们可以在Asp.net core 5.0中使用哪一个吗?

Currently almost all of the encryption algorithms start giving me errors when I switch the project type from Asp.net 5.0 to Asp.net 5.0 Core. This is because they all require System.Security.Cryptography namespance, which is not available in Core 5.0. See some code examples here. Any idea which one we could use in Asp.net core 5.0?

推荐答案

您应该使用Microsoft.AspNet.Security.DataProtection程序包.您可以使用的2个主要界面是:

You should use the Microsoft.AspNet.Security.DataProtection package. The 2 main interfaces you can use are:

https://github.com com/aspnet/DataProtection/blob/dev/src/Microsoft.AspNet.Security.DataProtection/IDataProtectionProvider.cs

https://github.com com/aspnet/DataProtection/blob/dev/src/Microsoft.AspNet.Security.DataProtection/IDataProtector.cs

在您的Web应用程序中,在ConfigureServices方法内,调用服务集合上的AddDataProtection以使其可用.

In your web application, within the ConfigureServices method, call AddDataProtection on the service collection to make these available.

从那里,您应该能够通过依赖项注入访问IDataProtectionProvider.

From there, you should be able to access the IDataProtectionProvider via dependency injection.

这篇关于我们在Asp.net 5 Core中使用哪种加密算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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