sookyboo Posted November 21, 2007 Share Posted November 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/78186-openssl-x509-certificate-problems/ Share on other sites More sharing options...
teng84 Posted November 21, 2007 Share Posted November 21, 2007 check if the file you're trying to open really exist! Quote Link to comment https://forums.phpfreaks.com/topic/78186-openssl-x509-certificate-problems/#findComment-395654 Share on other sites More sharing options...
sookyboo Posted November 21, 2007 Author Share Posted November 21, 2007 it does, I can display the file's content with an echo. Quote Link to comment https://forums.phpfreaks.com/topic/78186-openssl-x509-certificate-problems/#findComment-395782 Share on other sites More sharing options...
mithnik Posted June 16, 2009 Share Posted June 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/78186-openssl-x509-certificate-problems/#findComment-857421 Share on other sites More sharing options...
danbars Posted October 31, 2009 Share Posted October 31, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/78186-openssl-x509-certificate-problems/#findComment-948430 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.