2023-06-12 15:58:19 +02:00
|
|
|
== How to fix it in .NET
|
|
|
|
|
|
|
|
=== Code examples
|
|
|
|
|
|
|
|
include::../../common/fix/code-rationale.adoc[]
|
|
|
|
|
|
|
|
==== Noncompliant code example
|
|
|
|
|
2023-08-15 14:19:27 +02:00
|
|
|
[source,csharp,diff-id=11,diff-type=noncompliant]
|
2023-06-12 15:58:19 +02:00
|
|
|
----
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
|
|
public void encrypt()
|
|
|
|
{
|
|
|
|
var simpleDES = new DESCryptoServiceProvider(); // Noncompliant
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
|
2023-08-15 14:19:27 +02:00
|
|
|
[source,csharp,diff-id=11,diff-type=compliant]
|
2023-06-12 15:58:19 +02:00
|
|
|
----
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
|
|
public void encrypt()
|
|
|
|
{
|
|
|
|
using (Aes aes = Aes.Create())
|
|
|
|
{
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
=== How does this work?
|
|
|
|
|
|
|
|
include::../../common/fix/strong-cryptography.adoc[]
|
|
|
|
|