Jump to content


openssl x509 certificate problems

  • Please log in to reply
4 replies to this topic

#1 sookyboo

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 November 2007 - 04:13 AM

I have a .cer file (generated from a jsp server I think).

I need to extract it's public key and use the public key to encrypt a value...

I get these errors:
Warning: openssl_x509_read() [function.openssl-x509-read]: supplied parameter cannot be coerced into an X509 certificate! in /public_html/test/cert.php on line 26

Warning: openssl_x509_free() expects parameter 1 to be resource, string given in /public_html/test/cert.php on line 34

    $fp = fopen("/home/x.cer", "r");
    $cert = fread($fp, 8192);

openssl_x509_read( $cert);
$data = openssl_x509_parse($cert);


openssl_x509_free( $cert );

Any ideas what is wrong...
Starting to get frustrated...
Thanks in advance

#2 teng84

  • Members
  • PipPipPip
  • Advanced Member
  • 3,576 posts
  • LocationPhilippines

Posted 21 November 2007 - 04:19 AM

check if the file you're trying to open really exist!

ako si Ronaldo bernal http://ronaldobernal.blogspot.com/

#3 sookyboo

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 November 2007 - 11:26 AM

it does, I can display the file's content with an echo.

#4 mithnik

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 16 June 2009 - 07:41 PM

Hi , it's my fisrt post in here, I hope this will help.

2 Do:

1. Generate a *.PEM certificate (Privacy Enhanced Mail) via Openssl command:

openssl pkcs12 -in  YOUR_pkcs12_certificate.pfx -out YOUR_NEW_CERTIFICATE.pem

2.The source code of PHP must be compiled with openssl option:

./configure --with-openssl=/usr


$cert = file_get_contents("OUR_NEW_CERTIFICATE.pem");
$ssl = openssl_x509_parse($cert);

4. Cheers

#5 danbars

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 31 October 2009 - 08:31 PM

I had the same issue and it turned out to be UTF-8 BOM.
In case you don't knoew what it means - it's 2 hidden characters at the beginning of a file that indicates it is encoded with UTF-8.
Notepad and other applications put it there by default.
To remove it:
If the file has only english characters (like certificates should have) - Open the file with notepad and click file>save as.
In the 'encoding' field select 'ANSI', and save the file.

Another option is to use HEX editor (I use xvi32 - free and good), and delete the first 2 characters.

I hope this helps someone...


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users