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:17
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: w3ricardo-php at yahoo dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC