PHP using openssl_verify to validate signature instance program _php Tutorial

Source: Internet
Author: User
Let's take a look at the PHP use openssl_verify verification Signature Instance program, hope this article will help you.
The code is as follows Copy Code


!--? php
/**

* Verify signature

* tobeverified to be verified signature redaction

* PlainText signature Clear Text

* Ce Rtfile signer Public key certificate

* Return validation successfully returns TRUE, Failure returns false (the reason for failure from the 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 (certificate not 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))
{ br>
//print ("www.bKjia.c0m prompts you: Verify success.")
");
return true;
}
Else
{

//echo "error number:-10021, error Description:er_verify_error (verification failed) |". Openssl_error_string ();
return false;
}

}

?;

Openssl_verify may have three return values of 1,0,-1, and only 1 is returned to verify that the signature was successful.

$signature _alg default OPENSSL_ALGO_SHA1, if DSA encryption is set to Openssl_algo_dss1

http://www.bkjia.com/PHPjc/632817.html www.bkjia.com true http://www.bkjia.com/PHPjc/632817.html techarticle Let's take a look at the PHP use openssl_verify verification Signature Instance program, hope this article will help you. Code to copy code as follows? PHP/** * Verify signature ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.