在我的C#到PHP代码转换中没有得到sha1匹配,我缺少了什么?

在我的C#到PHP代码转换中没有得到sha1匹配,我缺少了什么?,c#,php,hash,forms-authentication,sha1,C#,Php,Hash,Forms Authentication,Sha1,我正在努力理解这一点,这样我就可以做类似的事情。我知道: buf包含一个附加了哈希的身份验证密钥(最后20个字节) 在MachineKeySection中查找的哈希数据是SHA1 length -= 20; byte[] buffer2 = MachineKeySection.HashData(buf, null, 0, length); for (int i = 0; i < 20; i++) { if (buffer2[i] != buf[length + i]) {

我正在努力理解这一点,这样我就可以做类似的事情。我知道:

buf包含一个附加了哈希的身份验证密钥(最后20个字节) 在MachineKeySection中查找的哈希数据是SHA1

length -= 20;
byte[] buffer2 = MachineKeySection.HashData(buf, null, 0, length);

for (int i = 0; i < 20; i++)
{
    if (buffer2[i] != buf[length + i])
    {
        return null;
    }
}
下一步是比较。但是当我回显$hash和sha1($ticket)的输出时,它们不匹配,所以我甚至没有在代码中比较它们。

默认情况下,php返回一个40个字符的十六进制数。如果您需要20字节的二进制格式,则必须显式请求该格式

$ticket = substr($decrypthex, 0, -20);
$hash = substr($decrypthex, -20);
$hash = sha1( $ticket, true );
默认情况下,php返回一个40个字符的十六进制数。如果您需要20字节的二进制格式,则必须显式请求该格式

$hash = sha1( $ticket, true );

谢谢你提供了更好的语法,但仍然不是我需要的。谢谢你提供了更好的语法,但仍然不是我需要的。