php.net |  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
Votes:8
Avg. Score:4.0 ± 1.0
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:1 (20.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:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-02-28 16:42 UTC] w3ricardo-php at yahoo dot com
Description:
------------
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] pajoye@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: ab
 [2012-02-29 10:49 UTC] pajoye@php.net
To be documented, as the padding area in the openssl doc is rather small :)
 [2012-02-29 10:49 UTC] pajoye@php.net
-Type: Bug +Type: Documentation Problem
 [2012-02-29 10:50 UTC] pajoye@php.net
-Assigned To: ab +Assigned To:
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Mon Jul 24 04:01:40 2017 UTC