Open In App

PHP openssl_digest() Function

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 –

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
    
// Data for which digest is to be created
$data = 'geeks for geeks';
  
  
// openssl_digest() with sha512 algorithm
// to compute digest value true as
// parameters return the raw input
$fingerPrint = openssl_digest ($data , "sha512", true);
  
// Print the output of openssl_digest output
print_r($fingerPrint);
  
?>

Output :

o��P�R�:`�w�ce�V x���(�eH@\000�7��G�”

Example 2: 




<?php
    
// Data for which digest is to be created
$data = 'geeks for geeks';
  
  
// openssl_digest() with sha512 algorithm
// to compute digest value false as 
// parameters return the hex value
$fingerPrint = openssl_digest ($data , "sha512", false);
  
// Print the output of openssl_digest output
print_r($fingerPrint);
  
?>

Output:

6e5f36e9cee5cba6ad938977c98e12f3a61fc4d944753ad130116b026b8ab2c895878910fea3b47dba6d760a20d0b23233980a8dab13f04f262c53f25222b416

Reference: https://www.php.net/manual/en/function.openssl-pkey-export.php


Article Tags :