为什么要使用 C# 类 System.Random 而不是 System.Security.Cryptography.RandomNumberGenerator? [英] Why use the C# class System.Random at all instead of System.Security.Cryptography.RandomNumberGenerator?

查看:23
本文介绍了为什么要使用 C# 类 System.Random 而不是 System.Security.Cryptography.RandomNumberGenerator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么有人会使用 系统中的标准"随机数生成器.完全随机,而不是总是使用来自 System.Security.Cryptography.RandomNumberGenerator(或其子类,因为 RandomNumberGenerator 是抽象的)?

Why would anybody use the "standard" random number generator from System.Random at all instead of always using the cryptographically secure random number generator from System.Security.Cryptography.RandomNumberGenerator (or its subclasses because RandomNumberGenerator is abstract)?

Nate Lawson 在第 13 分钟的 Google Tech Talk 演讲加密反击"中告诉我们:11 不要使用来自 Python、Java 和 C# 的标准"随机数生成器,而是使用加密安全版本.

Nate Lawson tells us in his Google Tech Talk presentation "Crypto Strikes Back" at minute 13:11 not to use the "standard" random number generators from Python, Java and C# and to instead use the cryptographically secure version.

我知道两个版本的随机数生成器之间的区别(参见 问题 101337).

I know the difference between the two versions of random number generators (see question 101337).

但是不总是使用安全随机数生成器的理由是什么?为什么要使用 System.Random?也许性能?

But what rationale is there to not always use the secure random number generator? Why use System.Random at all? Performance perhaps?

推荐答案

速度和意图.如果您正在生成一个随机数并且不需要安全性,为什么要使用慢速加密功能?您不需要安全性,那么为什么要让其他人认为该号码可能被用于安全的事情,而实际上并不安全?

Speed and intent. If you're generating a random number and have no need for security, why use a slow crypto function? You don't need security, so why make someone else think that the number may be used for something secure when it won't be?

这篇关于为什么要使用 C# 类 System.Random 而不是 System.Security.Cryptography.RandomNumberGenerator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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