Jump to content


Photo

openssl x509 certificate problems


  • Please log in to reply
4 replies to this topic

#1 sookyboo

sookyboo

    Newbie

  • New Members
  • Pip
  • 4 posts

Posted 20 November 2007 - 11:13 PM

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);

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

print_r($data);

openssl_x509_free( $cert );



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



#2 teng84

teng84

    Advanced Member

  • Members
  • PipPipPip
  • 3,576 posts
  • LocationPhilippines

Posted 20 November 2007 - 11:19 PM

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

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

#3 sookyboo

sookyboo

    Newbie

  • New Members
  • Pip
  • 4 posts

Posted 21 November 2007 - 06:26 AM

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

#4 mithnik

mithnik

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 16 June 2009 - 02: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


3.
<?php

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

4. Cheers





#5 danbars

danbars

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 31 October 2009 - 03: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...

Cheers,
Dan




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com