简体   繁体   English

如何发送空字节数组的MD5哈希?

[英]How to send MD5 hash of empty byte array?

I need to send a request from PHP to a C# WEB API. 我需要从PHP向C#WEB API发送请求。 As part of the authentication it requires an MD5 hash of an empty byte array. 作为身份验证的一部分,它需要一个空字节数组的MD5哈希。

How can I generate an MD5 hash of an empty byte array on PHP? 如何在PHP上生成一个空字节数组的MD5哈希? I would do it like this in C#. 我会在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 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. 如果您无法用PHP计算它,则只需使用一个常量,对于空数组,请使用该哈希值。

You can do it in many way: 您可以通过多种方式进行操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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