DES, TripleDES and RC2 are all considered broken or insecure cryptographic algorithms.
If using .NET Framework greater than version 6.0 consider using ChaCha20Poly1305
instead as it is easier and faster than the alternatives such as AES-256-GCM.
For older applications, AES-256-GCM is recommended, however it has many drawbacks:
Slower than ChaCha20Poly1305.
Catastrophic failure if nonce values are reused.
Example using ChaCha20Poly1305:
// Generate a random key
byte[] key = new byte[32];
RandomNumberGenerator.Fill(key);
// Note nonce values _must_ be regenerated every time they are used.
byte[] nonce = new byte[12];
RandomNumberGenerator.Fill(nonce);
byte[] authTag = new byte[16];
byte[] cipherText;
using (ChaCha20Poly1305 encryptor = new ChaCha20Poly1305(key))
{
byte[] plainText = System.Text.Encoding.UTF8.GetBytes("Secret text to encrypt");
cipherText = new byte[plainText.Length];
encryptor.Encrypt(nonce, plainText, cipherText, authTag);
}
using (ChaCha20Poly1305 decryptor = new ChaCha20Poly1305(key))
{
byte[] output = new byte[cipherText.Length];
decryptor.Decrypt(nonce, cipherText, authTag, output);
Console.WriteLine("Output: {0}", System.Text.Encoding.UTF8.GetString(output));
}
Example using AES-256-GCM:
// Generate a random key
byte[] key = new byte[32];
RandomNumberGenerator.Fill(key);
// Note nonce values _must_ be regenerated every time they are used.
byte[] nonce = new byte[AesGcm.NonceByteSizes.MaxSize];
RandomNumberGenerator.Fill(nonce);
byte[] authTag = new byte[AesGcm.TagByteSizes.MaxSize];
byte[] cipherText;
using (AesGcm encryptor = new AesGcm(key))
{
byte[] plainText = Encoding.UTF8.GetBytes("Secret text to encrypt");
cipherText = new byte[plainText.Length];
encryptor.Encrypt(nonce, plainText, cipherText, authTag);
}
using (AesGcm decryptor = new AesGcm(key))
{
byte[] output = new byte[cipherText.Length];
decryptor.Decrypt(nonce, cipherText, authTag, output);
Console.WriteLine("Output: {0}", Encoding.UTF8.GetString(output));
}
## medium Finding
**Scanner:** semgrep
**Severity:** medium
**Rule:** gitlab-csharp_crypto_rule-WeakCipherAlgorithm
**CWE:** CWE-327
**CRA:** cra-ai-13 — Verschlüsselung sensibler Daten (Annex I)
### Description
DES, TripleDES and RC2 are all considered broken or insecure cryptographic algorithms.
If using .NET Framework greater than version 6.0 consider using `ChaCha20Poly1305`
instead as it is easier and faster than the alternatives such as `AES-256-GCM`.
For older applications, `AES-256-GCM` is recommended, however it has many drawbacks:
- Slower than `ChaCha20Poly1305`.
- Catastrophic failure if nonce values are reused.
Example using `ChaCha20Poly1305`:
```
// Generate a random key
byte[] key = new byte[32];
RandomNumberGenerator.Fill(key);
// Note nonce values _must_ be regenerated every time they are used.
byte[] nonce = new byte[12];
RandomNumberGenerator.Fill(nonce);
byte[] authTag = new byte[16];
byte[] cipherText;
using (ChaCha20Poly1305 encryptor = new ChaCha20Poly1305(key))
{
byte[] plainText = System.Text.Encoding.UTF8.GetBytes("Secret text to encrypt");
cipherText = new byte[plainText.Length];
encryptor.Encrypt(nonce, plainText, cipherText, authTag);
}
using (ChaCha20Poly1305 decryptor = new ChaCha20Poly1305(key))
{
byte[] output = new byte[cipherText.Length];
decryptor.Decrypt(nonce, cipherText, authTag, output);
Console.WriteLine("Output: {0}", System.Text.Encoding.UTF8.GetString(output));
}
```
Example using `AES-256-GCM`:
```
// Generate a random key
byte[] key = new byte[32];
RandomNumberGenerator.Fill(key);
// Note nonce values _must_ be regenerated every time they are used.
byte[] nonce = new byte[AesGcm.NonceByteSizes.MaxSize];
RandomNumberGenerator.Fill(nonce);
byte[] authTag = new byte[AesGcm.TagByteSizes.MaxSize];
byte[] cipherText;
using (AesGcm encryptor = new AesGcm(key))
{
byte[] plainText = Encoding.UTF8.GetBytes("Secret text to encrypt");
cipherText = new byte[plainText.Length];
encryptor.Encrypt(nonce, plainText, cipherText, authTag);
}
using (AesGcm decryptor = new AesGcm(key))
{
byte[] output = new byte[cipherText.Length];
decryptor.Decrypt(nonce, cipherText, authTag, output);
Console.WriteLine("Output: {0}", Encoding.UTF8.GetString(output));
}
```
### Location
**File:** `compliance-agent/rules/cra_semgrep_csharp.cs` (line 193)
### Code
```
var des = new DESCryptoServiceProvider();
```
---
*Fingerprint:* `d68d97685ced69d8c2a1c4e2fc6c9b52321c460d0cde6b0f4017b63353977fbc`
*Generated by compliance-scanner*
[Open in Prüfwerk / In Prüfwerk öffnen](https://pruefwerk.breakpilot.com/findings?target=6ae9aa2160f5d8045fc570a7)
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
medium Finding
Scanner: semgrep
Severity: medium
Rule: gitlab-csharp_crypto_rule-WeakCipherAlgorithm
CWE: CWE-327
CRA: cra-ai-13 — Verschlüsselung sensibler Daten (Annex I)
Description
DES, TripleDES and RC2 are all considered broken or insecure cryptographic algorithms.
If using .NET Framework greater than version 6.0 consider using
ChaCha20Poly1305instead as it is easier and faster than the alternatives such as
AES-256-GCM.For older applications,
AES-256-GCMis recommended, however it has many drawbacks:ChaCha20Poly1305.Example using
ChaCha20Poly1305:Example using
AES-256-GCM:Location
File:
compliance-agent/rules/cra_semgrep_csharp.cs(line 193)Code
Fingerprint:
d68d97685ced69d8c2a1c4e2fc6c9b52321c460d0cde6b0f4017b63353977fbcGenerated by compliance-scanner
Open in Prüfwerk / In Prüfwerk öffnen
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.