logo

Database

Php Rsa No Padding

Description

This detector identifies RSA encryption/decryption operations that use no padding or unsafe padding schemes. RSA without proper padding is vulnerable to various cryptographic attacks including chosen plaintext attacks and can leak information about the encrypted data.

Weakness:

052 - Insecure encryption algorithm

Category: Information Collection

Detection Strategy

    Scans PHP code for calls to OpenSSL RSA functions that handle encryption, decryption, signing, or verification operations

    Identifies when these RSA functions are called with padding arguments that specify no padding or unsafe padding constants

    Reports a vulnerability when RSA cryptographic operations explicitly disable padding protection mechanisms

Vulnerable code example

<?php

function encryptData($plaintext, $publicKey) {
    // VULNERABLE: OPENSSL_NO_PADDING disables RSA padding, making encryption deterministic and malleable
    openssl_public_encrypt($plaintext, $encrypted, $publicKey, OPENSSL_NO_PADDING);
    return $encrypted;
}
...

✅ Secure code example

<?php

function encryptData($plaintext, $publicKey) {
    // SAFE: OPENSSL_PKCS1_OAEP_PADDING provides secure, non-deterministic encryption
    openssl_public_encrypt($plaintext, $encrypted, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
    return $encrypted;
}
...