> For the complete documentation index, see [llms.txt](https://docs.sec1.io/user-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sec1.io/user-docs/4-sast/2-java/usage-of-cbc-mode-with-padding.md).

# Usage of CBC (Cipher Block Chaining) Mode with Padding

## Overview

* **Rule ID**: `java_lang_padding_oracle_encryption_vulnerability`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-327

## Description

Using a block cipher algorithm mode like CBC (Cipher Block Chaining) with a padding scheme is susceptible to Padding Oracle attacks. This vulnerability occurs because attackers can exploit the padding scheme to decrypt messages.

## Remediation Guidelines

* **Avoid** using CBC mode with padding for encryption, as this combination is vulnerable to security breaches.

  ```java
  Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding"); // unsafe
  ```
* **Instead, consider using GCM (Galois/Counter Mode)** for encryption implementation. GCM provides a more secure alternative that mitigates the risks associated with CBC mode.

  ```java
  Cipher c = Cipher.getInstance("AES/GCM/PKCS5Padding");
  ```

## References

* [**Java Cipher class**](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/javax/crypto/Cipher.html)
* [**Java Security Standard Algorithm Names**](https://docs.oracle.com/en/java/javase/20/docs/specs/security/standard-names.html)
* [**CWE-327: Use of a Broken or Risky Cryptographic Algorithm**](https://cwe.mitre.org/data/definitions/327.html)
* [**OWASP Top 10: A02:2021 - Cryptographic Failures**](https://owasp.org/Top10/A02_2021-Cryptographic_Failures/)

## Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our [**SAST TOOL**](https://scopy.sec1.io/login)
