Which encryption algorithm do we use in Asp.net 5 Core

女生的网名这么多〃 提交于 2019-12-12 15:26:53

问题


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?


回答1:


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

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

and

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

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

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



来源:https://stackoverflow.com/questions/27884517/which-encryption-algorithm-do-we-use-in-asp-net-5-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!