== How to fix it in .NET

=== Code examples

==== Noncompliant code example

include::../../common/fix/aes-noncompliant-example.adoc[]

[source,vbnet,diff-id=1,diff-type=noncompliant]
----
Imports System.Security.Cryptography

Public Module Example

    Public Sub Encrypt()
        Dim Algorithm As New AesManaged() With {
            .KeySize = 128,
            .BlockSize = 128,
            .Mode = CipherMode.ECB, ' Noncompliant
            .Padding = PaddingMode.PKCS7
            }
    End Sub
End Module
----

include::../../common/fix/rsa-noncompliant-example.adoc[]

[source,vbnet,diff-id=2,diff-type=noncompliant]
----
Imports System.Security.Cryptography

Public Module Example

    Public Sub Encrypt()
        Dim data(10) As Byte
        Dim RsaCsp = New RSACryptoServiceProvider()
        RsaCsp.Encrypt(data, False) ' Noncompliant
    End Sub
End Module
----


==== Compliant solution

include::../../common/fix/aes-compliant-example.adoc[]

[source,vbnet,diff-id=1,diff-type=compliant]
----
Imports System.Security.Cryptography

Public Module Example

    Public Sub Encrypt()
        Dim data(10) As Byte
        Dim Algorithm As New AesGcm(data)
    End Sub
End Module
----


include::../../common/fix/rsa-compliant-example.adoc[]

[source,vbnet,diff-id=2,diff-type=compliant]
----
Imports System.Security.Cryptography

Public Module Example

    Public Sub Encrypt()
        Dim data(10) As Byte
        Dim RsaCsp = New RSACryptoServiceProvider()
        RsaCsp.Encrypt(data, True) ' Noncompliant
    End Sub
End Module
----

=== How does this work?

include::../../common/fix/fix.adoc[] 
