我试图理解这一点,所以我可以做类似的事情。我知道:
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) 的输出时,它们不匹配,所以我什至没有费心在代码中比较它们。