NYCPHP Meetup

NYPHP.org

[nycphp-talk] How to use the php_openssl_verify function

lee g8909183 at knight.fcu.edu.tw
Wed Feb 2 03:36:34 EST 2005


Hi :

This is my php program. I have some questions in line “$ok = openssl_verify($datar, $signature, $pubkeyid);”. I don’t know how to extract the $data and $ signature value from my user certificate (04.pem). Please tell me how to do it. Thank you very much.

Best regards

Peter

 

<?php

// fetch public key from certificate and ready it

$fp = fopen("cacert.pem", "r");

$cert = fread($fp, 8192);

fclose($fp);

$pubkeyid = openssl_get_publickey($cert);

 

// load user cert

 $fp = fopen("04.pem", "r");

 $cert1 = fread($fp, 8192);

 fclose($fp);

$cert2=openssl_x509_read($cert1);

$cert_data=(openssl_x509_parse($cert2));

 

// state whether signature is okay or not

$ok = openssl_verify($data, $signature, $pubkeyid);

if ($ok == 1) {

   echo "good";

} elseif ($ok == 0) {

   echo "bad";

} else {

   echo "ugly, error checking signature";

}

openssl_free_key($pubkeyid);

   openssl_x509_free( $cert2 );

?>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20050202/c962c63c/attachment.html>


More information about the talk mailing list