The code is as follows |
Copy Code |
<?php /**
* Verify Signature
* Tobeverified to be verified signed ciphertext
* PlainText the plaintext of the signature to be verified
* CertFile signer's public key certificate
* Return validation successfully returns TRUE, Failure returns false (reason for failure from lasterrmsg property)
*/ function verifymsg ($TobeVerified, $PlainText, $CertFile, $signature _alg=openssl_algo_sha1) {
Check with public key $FP =fopen ($CertFile, "R"); if (! $fp) {
echo "Error number:-10005, error description:er_find_cert_failed (Cannot find certificate)"; return false; } $pub _key=fread ($fp, 8192); Fclose ($FP); $res = Openssl_get_publickey ($pub _key); if (1==openssl_verify ($PlainText, Pack ("H". strlen ($TobeVerified), $TobeVerified), $res, $signature _alg)) {
Print ("Www.111cn.net prompts you: Verify success". "<br>"); return true; } Else {
echo "Error number:-10021, error description:er_verify_error (verification failure) |". Openssl_error_string (); return false; }
}
?> |
Openssl_verify may have three return value 1,0,-1, only 1 to indicate successful verification signatures.
$signature _alg default OPENSSL_ALGO_SHA1, if DSA encryption is set to Openssl_algo_dss1