Събитие
Създаване на интелигентни приложения
17.03, 23 ч. - 21.03, 23 ч.
Присъединете се към поредицата срещи, за да изградите мащабируеми AI решения, базирани на реални случаи на употреба с колеги разработчици и експерти.
Регистрирайте се сегаТози браузър вече не се поддържа.
Надстройте до Microsoft Edge, за да се възползвате от най-новите функции, актуализации на защитата и техническа поддръжка.
Property | Value |
---|---|
Rule ID | CA5401 |
Title | Do not use CreateEncryptor with non-default IV |
Category | Security |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 9 | No |
Using System.Security.Cryptography.SymmetricAlgorithm.CreateEncryptor with non-default rgbIV
.
Symmetric encryption should always use a non-repeatable initialization vector to prevent dictionary attacks.
This rule is similar to CA5402, but analysis determines that the initialization vector is definitely the default.
Use the default rgbIV
value, that is, use the overload of the System.Security.Cryptography.SymmetricAlgorithm.CreateEncryptor which doesn't have any parameter.
It's safe to suppress a warning from this rule if:
rgbIV
parameter was generated by System.Security.Cryptography.SymmetricAlgorithm.GenerateIV.rgbIV
is really random and non-repeatable.If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable CA5401
// The code that's violating the rule is on this line.
#pragma warning restore CA5401
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA5401.severity = none
For more information, see How to suppress code analysis warnings.
using System.Security.Cryptography;
class ExampleClass
{
public void ExampleMethod(byte[] rgbIV)
{
AesCng aesCng = new AesCng();
aesCng.IV = rgbIV;
aesCng.CreateEncryptor();
}
}
using System.Security.Cryptography;
class ExampleClass
{
public void ExampleMethod()
{
AesCng aesCng = new AesCng();
aesCng.CreateEncryptor();
}
}
Обратна връзка за .NET
.NET е проект с отворен код. Изберете връзка, за да предоставите обратна връзка:
Събитие
Създаване на интелигентни приложения
17.03, 23 ч. - 21.03, 23 ч.
Присъединете се към поредицата срещи, за да изградите мащабируеми AI решения, базирани на реални случаи на употреба с колеги разработчици и експерти.
Регистрирайте се сега