我使用ASP.NET 5模板创建了一个新的Web项目。我希望使用System.Security.Cryptography.RandomNumberGenerator生成随机数,但在.NET平台5.4中没有它(见屏幕快照)。

编译它还会产生以下错误:
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是否有一种使用此方法的方法,或者是否有一种我可以使用的具有密码安全性的随机生成器?
发布于 2015-12-17 23:28:09
多亏了斯科特·张伯伦( Scott )的评论,我才让它发挥作用,增加了System.Security.Cryptography.Algorithms NuGet软件包。
我还必须修改project.json,因此它只是dotnet5.4的依赖项,而不是全局依赖项,否则编译器会抱怨RandomNumberGenerator同时存在于System.Security.Cryptography.Algorithms和mscorlib中。
https://stackoverflow.com/questions/34345271
复制相似问题