This question already has an answer here:
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 ?
</div>
file_get_contents()
, it's far simpler.openssl_get_publickey($cert)
return?Try:
function der2pem($der_data) {
$pem = chunk_split(base64_encode($der_data), 64, "
");
$pem = "-----BEGIN CERTIFICATE-----
".$pem."-----END CERTIFICATE-----
";
return $pem;
}
$cert = der2pem(file_get_contents('C:/Users/User/Desktop/xampp/htdocs/pubkey.der'));
if( ! $pubkeyid = openssl_get_publickey($cert) ) {
throw new \Exception(openssl_error_string());
}