简体   繁体   中英

How to send MD5 hash of empty byte array?

I need to send a request from PHP to a C# WEB API. As part of the authentication it requires an MD5 hash of an empty byte array.

How can I generate an MD5 hash of an empty byte array on PHP? I would do it like this in C#.

byte[] Content = new byte[0];
using (var md5 = MD5.Create())
{
  return md5.ComputeHash(content);
}

https://superuser.com/questions/557925/how-can-zero-byte-files-generate-a-hash-value

If you can't compute it in PHP, then just use a constant and, for empty array, use that hash value.

You can do it in many way:

$hash = md5(null, true);
// or
$hash = md5('', true);
// or
$hash = md5(false, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM