(PHP 5 >= 5.3.0, PHP 7, PHP 8)

openssl_digestComputes a digest

OpenSSL's command line is not designed to be flexible, it's more of a quick-and-dirty way to perform cryptographic calculations from the command line. If you want to use OpenSSL, filter the output: echo -n 'foo' openssl dgst -sha1 sed 's/^.

Openssl Dgst Sha256

Description

openssl_digest ( string$data , string$digest_algo , bool$binary = false ) : stringfalse

Computes a digest hash value for the given data using a given method, and returns a raw or binhex encoded string.

  • Openssl dgst -sha256 -binary gives you a SHA256 binary checksum for the file. The second part of the command: openssl enc -base64 encodes the SHA256 binary checksum to Base64.
  • Somehow the OpenSSL HMAC(EVPsha256, does not produce the same hmac for Keys that are longer than SHA256 key len. Your function creates a new SHA256 hash if the key is longer than 32 bytes. The hmac both functions then produce are different. Nevermind: I had the message and key args mixed up.

Parameters

data

The data.

digest_algo

The digest method to use, e.g. 'sha256', see openssl_get_md_methods() for a list of available digest methods.

binary

Setting to true will return as raw output data, otherwise the return value is binhex encoded.

Return Values

Returns the digested hash value on success or false on failure.

Errors/Exceptions

Emits an E_WARNING level error if an unknown signature algorithm is passed via the digest_algo parameter.

See Also

  • openssl_get_md_methods() - Gets available digest methods
mwgamera at gmail dot com
7 years ago
The second argument should be one of the values returned by openssl_get_md_methods() rather than hash_algos(). ‘Hash’ and ‘OpenSSL’ are independent extensions and support different selection of digest algorithms. Notably, Hash supports some non-cryptographic hashes like adler or crc.
skyblackhawk at yahoo dot it

Openssl Dgst Sign

9 years ago
Example:
// $fileBuffer is buffer of file in open mode or a generic stream...
$fingerPrint = openssl_digest ($fileBuffer , 'sha512');
$method parameter is one of hash_algos() array;
<? echo'<PRE>';
var_dump(hash_algos());
echo '</PRE>'
?>
Output:
array(42) {
[0]=>
string(3) 'md2'
[1]=>
string(3) 'md4'
[2]=>
string(3) 'md5'
[3]=>
string(4) 'sha1'
[4]=>
string(6) 'sha224'
[5]=>
string(6) 'sha256'
[6]=>
string(6) 'sha384'
[7]=>
string(6) 'sha512'
[8]=>
string(9) 'ripemd128'
[9]=>
string(9) 'ripemd160'
[10]=>
string(9) 'ripemd256'
[11]=>
string(9) 'ripemd320'
[12]=>
string(9) 'whirlpool'
[13]=>
string(10) 'tiger128,3'
[14]=>
string(10) 'tiger160,3'
[15]=>
string(10) 'tiger192,3'
[16]=>
string(10) 'tiger128,4'
[17]=>
string(10) 'tiger160,4'
[18]=>
string(10) 'tiger192,4'
[19]=>
string(6) 'snefru'
[20]=>
string(9) 'snefru256'
[21]=>
string(4) 'gost'
[22]=>
string(7) 'adler32'
[23]=>
string(5) 'crc32'
[24]=>
string(6) 'crc32b'
[25]=>
string(7) 'salsa10'
[26]=>
string(7) 'salsa20'
[27]=>
string(10) 'haval128,3'
[28]=>
string(10) 'haval160,3'
[29]=>
string(10) 'haval192,3'
[30]=>
string(10) 'haval224,3'
[31]=>
string(10) 'haval256,3'
[32]=>
string(10) 'haval128,4'
[33]=>
string(10) 'haval160,4'
[34]=>
string(10) 'haval192,4'
[35]=>
string(10) 'haval224,4'
[36]=>
string(10) 'haval256,4'
[37]=>
string(10) 'haval128,5'
[38]=>
string(10) 'haval160,5'
[39]=>
string(10) 'haval192,5'
[40]=>
string(10) 'haval224,5'
[41]=>
string(10) 'haval256,5'
}
Anonymous

Sha256 Command Line

6 years ago

Openssl Dgst -sha256

Hmm.. really @mwgamera? openssl_get_cipher_methods() returns cipher methods but openssl_digest() expects a digest method in the second parameter. However even the docu on this page links to the openssl_get_cipher_methods() method in the 'See also' section (however this can be a coincidence). Shouldn't it be a digest method from openssl_get_md_methods() instead openssl_get_cipher_methods()?
I'm not very experienced in cryptography but I don't really understand why you would pass a cipher method to a hash function instead of a digest method.

Openssl Dgst Sha256 String

  • OpenSSL Functions
Coments are closed

Most Viewed Posts

  • Teams Via Web
  • Excel Combine Pivot Tables
  • Fire Stick 4k Retroarch
  • Openssl Wiki
  • Retroarch Atari Jaguar

Scroll to top