Php uses openssl_verify to verify the signature instance program. Next let's take a look at the example program for verifying the signature using openssl_verify in php. I hope this article will be helpful to you. The code is as follows: Copy the code? Php *** to verify the signature, let's take a look at php's use of openssl_verify to verify the signature instance program. I hope this article will be helpful to you.
The code is as follows: |
|
/** * Verify the signature * TobeVerified the ciphertext of the signature to be verified * PlainText of the signature to be verified * CertFile: public key certificate of the signatory * If return is verified successfully, true is returned. if return fails, false is returned (the cause of failure is obtained from the LastErrMsg attribute) */ Function VerifyMsg ($ TobeVerified, $ PlainText, $ CertFile, $ signature_alg = OPENSSL_ALGO_SHA1) { // Use the public key for signature verification $ Fp = fopen ($ CertFile, "r "); If (! $ Fp) { // Echo "Error Number:-10005, Error Description: ER_FIND_CERT_FAILED (the certificate cannot be found )"; 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. bKjia. c0m prompts you: verification successful "." "); Return true; } Else { // Echo "Error Number:-10021, Error Description: ER_VERIFY_ERROR (signature verification failed) |". openssl_error_string (); Return false; } } ?>
|
Openssl_verify may return values 1, 0,-1. only 1 indicates that the signature is successfully verified.
$ Signature_alg: OPENSSL_ALGO_SHA1 by default. if it is DSA encryption, set it to OPENSSL_ALGO_DSS1.
Use openssl_verify to verify the signature instance program. I hope this article will help you. The code is as follows? Php/*** verify the signature...