|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61203 RSA encryption fails without padding
Submitted: 2012-02-28 16:42 UTC Modified: 2012-02-29 10:50 UTC
Avg. Score:3.9 ± 1.1
Reproduced:10 of 11 (90.9%)
Same Version:3 (30.0%)
Same OS:3 (30.0%)
From: w3ricardo-php at yahoo dot com Assigned:
Status: Open Package: OpenSSL related
PHP Version: 5.3.10 OS: Windows 7 Professional 32 bits
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
39 + 7 = ?
Subscribe to this entry?

 [2012-02-28 16:42 UTC] w3ricardo-php at yahoo dot com
openssl_public_encrypt fails with the argument OPENSSL_NO_PADDING. Without it, it works fine.

Test script:
$configargs = array
   ("private_key_bits" => 4096,
    "private_key_type" => OPENSSL_KEYTYPE_RSA,
    "encrypt_key" => false);
$key = openssl_pkey_new($configargs);
$details = openssl_pkey_get_details($pubkey);
$pubkey = $details['key'];
$r = openssl_public_encrypt("This is a test", $crypted, $pubkey, OPENSSL_NO_PADDING);
if ($r) {
  echo "encrypt no padding: true\n";
} else {
  echo "encrypt no padding: false\n";
  $r = openssl_public_encrypt("This is a test", $crypted, $pubkey);
  if ($r) {
    echo "encrypt with padding: true\n";
  } else {
    echo "encrypt with padding: false\n";

Expected result:
encrypt no padding: true

Actual result:
encrypt no padding: false
encrypt with padding: true


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-28 18:15 UTC] w3ricardo-php at yahoo dot com
If you provide the data with the correct size, by appending "\0"s for example, the function works. Now it's obvious, after two days of work. Maybe the documentation should address that.
 [2012-02-29 09:33 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: ab
 [2012-02-29 10:49 UTC]
To be documented, as the padding area in the openssl doc is rather small :)
 [2012-02-29 10:49 UTC]
-Type: Bug +Type: Documentation Problem
 [2012-02-29 10:50 UTC]
-Assigned To: ab +Assigned To:
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Mar 28 22:03:42 2023 UTC