0

我试图理解这一点,所以我可以做类似的事情。我知道:

buf 包含一个附加了哈希的身份验证密钥(最后 20 个字节) 在 MachineKeySection 中查找的 HashData 是 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;
    }
}

这就是我认为正在发生的事情:我们正在散列除 buf 的最后 20 个字节之外的所有内容。然后,我们一次 1 个字节,将我们刚刚创建的散列与附加到 buf 的最后 20 个字节的散列进行比较。

所以在PHP中我正在尝试这个:

//get the length of the ticket -20 bytes
$ticketLn = strlen($buf)-40;
//grab all but the last 20 bytes
$ticket = substr($decrypthex, 0, $ticketLn);
//create a hash of the ticket
$hash = substr($decrypthex, $ticketLn);

下一步是比较。但是当我回显 $hash 和 sha1($ticket) 的输出时,它们不匹配,所以我什至没有费心在代码中比较它们。

4

2 回答 2

2

默认情况下,php 的sha1() 函数返回一个 40 个字符的十六进制数。如果这是您想要的,您必须明确请求 20 字节的二进制格式

$hash = sha1( $ticket, true );
于 2009-03-03T16:29:42.630 回答
1
$ticket = substr($decrypthex, 0, -20);
$hash = substr($decrypthex, -20);
于 2009-03-03T16:14:51.307 回答