2020-12-21 15:38:52 +01:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
public void Encrypt(byte[] key, byte[] data, MemoryStream target)
|
|
|
|
{
|
|
|
|
byte[] initializationVector = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
|
|
|
|
|
|
|
|
using var aes = new AesCryptoServiceProvider();
|
|
|
|
var encryptor = aes.CreateEncryptor(key, initializationVector); // Noncompliant, hardcoded value is used
|
|
|
|
|
|
|
|
using var cryptoStream = new CryptoStream(target, encryptor, CryptoStreamMode.Write);
|
|
|
|
cryptoStream.Write(data);
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
----
|
|
|
|
public byte[] Encrypt(byte[] key, byte[] data, MemoryStream target)
|
|
|
|
{
|
|
|
|
using var aes = new AesCryptoServiceProvider();
|
|
|
|
var encryptor = aes.CreateEncryptor(key, aes.IV); // aes.IV is automatically generated to random secure value
|
|
|
|
|
|
|
|
using var cryptoStream = new CryptoStream(target, encryptor, CryptoStreamMode.Write);
|
|
|
|
cryptoStream.Write(data);
|
|
|
|
|
|
|
|
return aes.IV;
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|