PHP openssl_digest() Function
Last Updated :
27 Oct, 2021
The openssl_digest() function is an inbuilt function in PHP that is used to compute a digest hash value for the given data using a given method and returns a raw or binary hex-encoded string.
Syntax:
openssl_digest( string $data, string $digest_algo,
bool $binary = false): string|false
Parameters: This function accepts four parameters as mentioned above and described below –
- data: The data for which digest value is to be created.
- digest_algo: The digest method to use, e.g. “sha256”.
- binary: Setting to true will return as raw output data, otherwise the return value is binhex encoded.
Return Values: It returns the digested hash value on success or false on failure.
Below program illustrate the openssl_digest() function in PHP.
Example 1:
PHP
<?php
$data = 'geeks for geeks' ;
$fingerPrint = openssl_digest ( $data , "sha512" , true);
print_r( $fingerPrint );
?>
|
Output :
o��P�R�:`�w�ce�V x���(�eH@\000�7��G�”
Example 2:
PHP
<?php
$data = 'geeks for geeks' ;
$fingerPrint = openssl_digest ( $data , "sha512" , false);
print_r( $fingerPrint );
?>
|
Output:
6e5f36e9cee5cba6ad938977c98e12f3a61fc4d944753ad130116b026b8ab2c895878910fea3b47dba6d760a20d0b23233980a8dab13f04f262c53f25222b416
Reference: https://www.php.net/manual/en/function.openssl-pkey-export.php
Share your thoughts in the comments
Please Login to comment...