rspec/rules/S3329/vbnet/rule.adoc
2022-02-04 16:28:24 +00:00

49 lines
1.3 KiB
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
[source,vbnet]
----
Public Sub Encrypt(Key() As Byte, Data() As Byte, Target As MemoryStream)
Dim InitializationVector As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
Using Aes As New AesCryptoServiceProvider()
Dim Encryptor As ICryptoTransform = Aes.CreateEncryptor(Key, InitializationVector) ' Noncompliant, hardcoded value Is used
Using CS As New CryptoStream(Target, Encryptor, CryptoStreamMode.Write)
CS.Write(Data)
End Using
End Using
End Sub
----
== Compliant Solution
[source,vbnet]
----
Public Sub Encrypt(Key() As Byte, Data() As Byte, Target As MemoryStream)
Using Aes As New AesCryptoServiceProvider()
Aes.GenerateIV()
Dim Encryptor As ICryptoTransform = Aes.CreateEncryptor(Key, Aes.IV)
Using CS As New CryptoStream(Target, Encryptor, CryptoStreamMode.Write)
CS.Write(Data)
End Using
End Using
End Sub
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]