This rule is deprecated; use {rule:php:S5542} instead.

## Why is this an issue?

Without OAEP in RSA encryption, it takes less work for an attacker to decrypt the data or infer patterns from the ciphertext. This rule logs an issue when `openssl_public_encrypt` is used with one the following padding constants: `OPENSSL_NO_PADDING` or `OPENSSL_PKCS1_PADDING` or `OPENSSL_SSLV23_PADDING`.

### Noncompliant code example

    function encrypt($data, $key) {
      $crypted='';
      openssl_public_encrypt($data, $crypted, $key, OPENSSL_NO_PADDING); // Noncompliant
      return $crypted;
    }

### Compliant solution

    function encrypt($data, $key) {
      $crypted='';
      openssl_public_encrypt($data, $crypted, $key, OPENSSL_PKCS1_OAEP_PADDING);
      return $crypted;
    }

## Resources

- OWASP - Top 10 2021 Category A2 - Cryptographic Failures
- OWASP - Top 10 2017 Category A3 - Sensitive Data Exposure
- OWASP - Top 10 2017 Category A6 - Security Misconfiguration
- CWE - CWE-780 - Use of RSA Algorithm without OAEP
- CWE - CWE-327 - Use of a Broken or Risky Cryptographic Algorithm
- Derived from FindSecBugs rule RSA NoPadding Unsafe