RandomNumberGenerator在ASP.NET5 [英] RandomNumberGenerator in ASP.NET5

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

问题描述

我已经创建使用ASP.NET 5模板一个新的Web API项目。我想用System.Security.Cryptography.RandomNumberGenerator生成随机数,但它不是在.NET平台5.4提供(见截图)。

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?

推荐答案

我把它加入System.Security.Cryptography.Algorithms的NuGet包工作的感谢Scott张伯伦的评论。

I got it working thanks to Scott Chamberlain's comment by adding the System.Security.Cryptography.Algorithms NuGet package.

我也不得不修改project.json所以这只是dotnet5.4的依赖,而不是一个全局依赖,否则编译器会抱怨RandomNumberGenerator存在于两个System.Security.Cryptography.Algorithms和mscorlib程序。

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.

这篇关于RandomNumberGenerator在ASP.NET5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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