C#idiomatic C#
ca5385fundamentals/code-analysis/quality-rules

Code analysis

CA5385: Use Rivest–Shamir–Adleman (RSA) algorithm with sufficient key size

Provides information about code analysis rule CA5385, including causes, how to fix violations, and when to suppress it.

CA5385 Security enabled by default in .NET 10: No
Fix is breaking or non-breaking Non-breakingApplicable languages C# and Visual Basic

Cause

Using asymmetric encryption algorithm RSA with key size less than 2048 in one of the following ways:

Rule description

An RSA key smaller than 2048 bits is more vulnerable to brute force attacks.

How to fix violations

Switch to an RSA with at least 2048 key size, ECDH or ECDsa algorithm instead.

When to suppress warnings

It is not recommended to suppress this rule unless for compatibility with legacy applications and data.

Suppress a warning

If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

csharp
#pragma warning disable CA5385
// The code that's violating the rule is on this line.
#pragma warning restore CA5385

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

ini
[*.{cs,vb}]
dotnet_diagnostic.CA5385.severity = none

For more information, see How to suppress code analysis warnings.

Example

The following code snippet illustrates the pattern detected by this rule.

Violation:

csharp
using System.Security.Cryptography;

class ExampleClass
{
    public void ExampleMethod()
    {
        RSACng rsaCng = new RSACng(1024);
    }
}

Solution:

csharp
using System.Security.Cryptography;

class ExampleClass
{
    public void ExampleMethod()
    {
        RSACng rsaCng = new RSACng(2048);
    }
}