openssl_verify

PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8
openssl_verify - Verify signature
Manual
Code Examples

openssl_verify(
     string$data,
     string$signature,
     OpenSSLAsymmetricKey|OpenSSLCertificate|array|string$public_key,
     [string|int$algorithm = OPENSSL_ALGO_SHA1]
): int|false

openssl_verify verifies that the signature is correct for the specified data using the public key associated with public_key. This must be the public key corresponding to the private key used for signing.

Parameters

data

The string of data used to generate the signature previously

signature

A raw binary string, generated by openssl_sign or similar means

public_key

OpenSSLAsymmetricKey - a key, returned by openssl_get_publickey

string - a PEM formatted key, example, "-----BEGIN PUBLIC KEY----- MIIBCgK..."

algorithm

int - one of these Signature Algorithms.

string - a valid string returned by openssl_get_md_methods example, "sha1WithRSAEncryption" or "sha512".

Return Values

Returns 1 if the signature is correct, 0 if it is incorrect, and -1 or false on error.

Changelog

Version Description
8.0.0 public_key accepts an OpenSSLAsymmetricKey or OpenSSLCertificate instance now; previously, a resource of type OpenSSL key or OpenSSL X.509 was accepted.

Related Functions

Example of openssl_verify

Show all examples for openssl_verify

PHP Version:


Function openssl_verify:

OpenSSL Functions

Most used PHP functions