用PHP验证签名的PDF文档

我有一份签名的PDF文件.它是使用TCPDF签署的.现在我想验证它.这是我的解决方案:

>获取已签名pdf的内容.
>根据/ ByRange字段获取原始内容和签名值.
>从签名值获取加密摘要消息.它是签名值末尾的八位字符串.
>使用Openssl_public_decrypt()函数使用公钥解密加密的摘要消息.然后我们有一个带有前缀的字符串(“3021300906052b0e03021a05000414”).此前缀表示使用的哈希函数是SHA-1.删除前缀后,我们获取摘要消息D1.
>使用SHA1()函数来散列原始内容,我们获取摘要消息D2.
>将D1与D2进行比较.如果D1 = D2则签名有效,反之亦然.

我的问题是在最后一步,当我将D1与D2进行比较时,它们并不相等.我不知道为什么.
谢谢你的帮助.

解决方法:

You should try based on following example
<?php
// $data and $signature are assumed to contain the data and the signature

// fetch public key from certificate and ready it
$pubkeyid = openssl_pkey_get_public("file://src/openssl-0.9.6/demos/sign/cert.pem");

// 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";
}
// free the key from memory
openssl_free_key($pubkeyid);
?>
more Examples ad explanation
 http://www.php.net/manual/en/function.openssl-verify.php
上一篇:npm install 插件时报错 -4048


下一篇:Mockito初探(一)—— 初识