ASP.NET5中的RandomNumberGenerator [英] RandomNumberGenerator in ASP.NET5
问题描述
我已经使用ASP.NET 5模板创建了一个新的Web API项目。我想使用System.Security.Cryptography.RandomNumberGenerator生成随机数,但它不可用的.NET平台5.4(见截图)。
编译它还会产生以下错误:
错误CS0234在命名空间System.Security中不存在类型或命名空间名称Cryptography(是否缺少程序集引用?)
错误CS0246类型或命名空间名称为RandomNumberGenerator '无法找到(是否缺少一个using指令或程序集引用?)
错误CS0103在当前上下文中不存在名称RandomNumberGenerator
有没有办法使用这个或者有一个替代的随机生成器,我可以使用它是加密安全的?
我得到它的工作感谢Scott Chamberlain的评论通过添加System.Security.Cryptography.Algorithms NuGet包。
我还必须修改project.json,这样它只是dotnet5.4的依赖,而不是全局依赖,否则编译器会抱怨RandomNumberGenerator存在于System.Security.Cryptography.Algorithms和mscorlib中。 p>
I have created a new Web API project using the ASP.NET 5 Templates. I am wanting to generate random numbers using System.Security.Cryptography.RandomNumberGenerator but it is not available in the .NET Platform 5.4 (see screenshot).
Compiling it also generates the following errors:
Error CS0234 The type or namespace name 'Cryptography' does not exist in the namespace 'System.Security' (are you missing an assembly reference?)
Error CS0246 The type or namespace name 'RandomNumberGenerator' could not be found (are you missing a using directive or an assembly reference?)
Error CS0103 The name 'RandomNumberGenerator' does not exist in the current context
Is there a way to use this or is there an alternative random generator that I can use which is cryptographically secure?
I got it working thanks to Scott Chamberlain's comment by adding the System.Security.Cryptography.Algorithms NuGet package.
I also had to modify the project.json so it was only a dependency of dotnet5.4 and not a global dependency otherwise the compiler would complain that RandomNumberGenerator exists in both System.Security.Cryptography.Algorithms and mscorlib.
这篇关于ASP.NET5中的RandomNumberGenerator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!