Encryption algorithms should use secure modes and padding schemes where appropriate to guarantee data confidentiality and integrity.

Noncompliant Code Example

Cipher.getInstance("AES") // Noncompliant: by default ECB mode is chosen
Cipher.getInstance("AES/ECB/NoPadding") // Noncompliant: ECB doesn't provide serious message confidentiality

Cipher.getInstance("AES/CBC/PKCS5Padding") // Noncompliant: Vulnerable to Padding Oracle attacks
Cipher.getInstance("RSA/None/NoPadding") // Noncompliant: RSA without OAEP padding scheme is not recommended

Compliant Solution

// Recommended for block ciphers
Cipher.getInstance("AES/GCM/NoPadding")

// Recommended for RSA
Cipher.getInstance("RSA/None/OAEPWITHSHA-256ANDMGF1PADDING")
// or the ECB mode can be used for RSA when "None" is not available with the security provider used - in that case, ECB will be treated as "None" for RSA.
Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING")

See