|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2003-09-20 12:27 UTC] six at t0x dot net
 Description: ------------ PHP manual states that : "openssl_pkey_new() generates a new private and public key pair. The public component of the key can be obtained using openssl_pkey_get_public()." However, the following script (see "reproduce-code" section) seems to indicate that openssl_pkey_get_public is broken in some way ... it should be noted that the two exports ($ex_k and $ex_p) start (and end) with a "RSA PRIVATE KEY" header line Reproduce code: --------------- <? $k = openssl_pkey_new(); $p = openssl_pkey_get_public($k); echo "php version ".phpversion()."\n\n"; echo "generated private key resource : $k\n"; echo "generated public key resource : $p\n\n"; openssl_pkey_export($k, $ex_k); openssl_pkey_export($p, $ex_p); if ($ex_k == $ex_p) echo "exports match :(\n"; ?> Expected result: ---------------- php version 4.3.3 generated private key resource : Resource id #4 generated public key resource : Resource id #5 Actual result: -------------- php version 4.3.3 generated private key resource : Resource id #4 generated public key resource : Resource id #4 exports match :( PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 23:00:01 2025 UTC | 
To fix this bug you have to change file php-4.4.0/ext/openssl/openssl.c. php-4.4.0 is just my source distributive of PHP. In file openssl.c replace string key = PEM_read_bio_PUBKEY(in, NULL,NULL, NULL); with another code RSA * rsa = PEM_read_bio_RSAPublicKey(in, NULL, NULL, NULL); BIO_free(in); if(NULL == rsa) { throw Exc("Error while processing the Public Key."); } pkey = EVP_PKEY_new(); EVP_PKEY_assign_RSA(pkey, rsa); Unsusccessfully I have no time to test it, but this must work. Hope to see this bugfix in a new release.