A cipher gets an initialization vector that is all zeros or derived from a literal, so equal messages encrypt equally

tx0/csharp:constant-initialization-vectorrecommendedwarningsecurity/cryptodepth fastsecurity, cwe-329

What it finds

The initialization vector makes two encryptions of the same plaintext differ. A fixed IV, such as new byte[16] or the bytes of a string literal, gives identical ciphertexts for identical messages and, with some modes, reveals more. A random IV per message, stored with the ciphertext, is the norm. The rule reports such values assigned to an IV property or passed as the second argument of CreateEncryptor.

From the rule's source, constant_initialization_vector.rs.

Example from the rule's tests
using System.Security.Cryptography;using System.Text; class Vault{    void Setup(Aes aes)    {        aes.IV = new byte[16];tx0 reports: the initialization vector is a constant        aes.IV = Encoding.UTF8.GetBytes("0123456789abcdef");tx0 reports: the initialization vector is a constant        aes.GenerateIV();    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:constant-initialization-vector" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:constant-initialization-vector] reason="..."

tx0 explain tx0/csharp:constant-initialization-vector shows the same in the terminal. Found a false positive? Report it.