This question already has an answer here:
- Supplied key param cannot be coerced into a private key with Google APIs 2 answers
I have this error with this file:
<?php
// $data and $signature are assumed to contain the data and the signature
$signature = null;
$toSign = "C:/Users/User/Desktop/xampp/htdocs/docum.docx";
$fp = fopen("key.pem", "r");
$priv_key = fread($fp, 8192);
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key);
openssl_sign($toSign, $signature, $pkeyid);
openssl_free_key($pkeyid);
echo($signature);
// fetch public key from certificate and ready it
$fp = fopen("C:/Users/User/Desktop/xampp/htdocs/pubkey.der", "r");
$cert = fread($fp, 8192);
fclose($fp);
$pubkeyid = openssl_get_publickey($cert);
// state whether signature is okay or not
$ok = openssl_verify($toSign, $signature, $pubkeyid);
if ($ok == 1) {
echo "good";
} elseif ($ok == 0) {
echo "bad";
} else {
echo "ugly, error checking signature";
}
// free the key from memory
openssl_free_key($pubkeyid);
?>
how can I fix this error ?`... I calculated the signature with the private key to the document, now I want to test it. at first I created two php files , the first one that signed the document , the second occurred ke me signing . I just do not know how to take the signature from the first documento.Ho decided to put it all together to try ... How can I fix ?