天天看點

php驗簽,用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

// $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

标簽:php,signature,tcpdf,verify,sign

來源: https://codeday.me/bug/20190708/1405324.html