- 필수 기능
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- 디지털 경험
- 소프트웨어 제공
- 보안
- 로그 관리
- 관리
- 인프라스트럭처
- ci
- containers
- csm
- ndm
- otel_guides
- overview
- slos
- synthetics
- tests
- 워크플로
ID: csharp-security/no-pseudo-random
Language: C#
Severity: Notice
Category: Security
CWE: 338
Avoid pseudo-random generator as they generate numbers that are easy to guess. Prefer more secure, cryptographic-friendly random generators.
class MyClass {
public static void routine()
{
var random = new Random();
var bytes = new byte[16];
var randomizeTwice = true;
var randomizeThrice = false;
random.NextBytes(bytes);
if (randomizeTwice) {
random.NextBytes(bytes);
}
if (randomizeThrice) {
new Random().NextBytes(bytes);
}
}
}
using System.Security.Cryptography;
class MyClass {
public static void routine()
{
var random = RandomNumberGenerator.Create();
byte[] randomData = new byte[4];
randomGenerator.GetBytes(randomData);
}
}
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products