---
title: Avoid using the insecure RC4 stream cipher
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid using the insecure RC4 stream cipher
---

# Avoid using the insecure RC4 stream cipher

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `rust-security/avoid-rc4`

**Language:** Rust

**Severity:** Warning

**Category:** Security

**CWE**: [327](https://cwe.mitre.org/data/definitions/327.html)

**Related CWEs**:

- [328](https://cwe.mitre.org/data/definitions/328.html)
- [916](https://cwe.mitre.org/data/definitions/916.html)
- [1240](https://cwe.mitre.org/data/definitions/1240.html)

## Description{% #description %}

RC4 has well-known statistical biases in its keystream and has been broken in real-world protocols including WEP and TLS. It must not be used for any security-sensitive operation. Use AES-256-GCM (via the `aes-gcm` crate) or another modern authenticated encryption algorithm instead.

#### Learn More{% #learn-more %}

- [CWE-327: Use of a Broken or Risky Cryptographic Algorithm](https://cwe.mitre.org/data/definitions/327.html)

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```rust
use rc4;
use rc4::Rc4;
use rc4::{Rc4, KeyInit};
use openssl::symm::Cipher;

fn invalid() {
    let key = [0u8; 16];

    // RustCrypto `rc4` crate
    let _ = rc4::Rc4::new_from_slice(&key);

    // openssl/boring `Cipher::rc4()` builder
    let _ = Cipher::rc4();
    let _ = openssl::symm::Cipher::rc4();
}
```

## Compliant Code Examples{% #compliant-code-examples %}

```rust
use aes_gcm::{Aes256Gcm, KeyInit};

fn ok() {
    // Safe: AES-256-GCM instead of RC4
    let key = [0u8; 32];
    let _ = Aes256Gcm::new(&key.into());
}
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 