【问题标题】:How to send MD5 hash of empty byte array?如何发送空字节数组的 MD5 哈希?
【发布时间】:2015-08-06 07:32:31
【问题描述】:

我需要从 PHP 向 C# WEB API 发送请求。 作为身份验证的一部分,它需要一个空字节数组的 MD5 哈希。

如何在 PHP 上生成空字节数组的 MD5 哈希? 我会在 C# 中这样做。

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

【问题讨论】:

  • md5('') - 错了吗?

标签: c# php asp.net web


【解决方案1】:

您可以通过多种方式做到这一点:

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

【讨论】:

  • 我忘了提到我正在进一步将散列值转换为 base64 字符串。但是 c# 代码和 PHP 生成的值不匹配。 PHP 代码:base64_encode(md5(null)) c# 代码:byte[] Content = new byte[0]; using (var md5 = MD5.Create()) { return Convert.ToBase64String(md5.ComputeHash(content)); }
  • PHP md5 生成一个十六进制字符串,所以我编辑了答案,将 raw_output 设置为 TRUE。立即尝试。
【解决方案2】:

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

如果您无法在 PHP 中计算它,那么只需使用一个常量,对于空数组,使用该哈希值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-18
    • 2011-01-27
    • 2011-11-15
    • 2012-08-17
    • 1970-01-01
    • 2012-05-28
    • 2022-08-11
    • 1970-01-01
    相关资源
    最近更新 更多