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

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)的输出时,它们不匹配,所以我甚至不打算在代码中比较它们。

有帮助吗?

解决方案

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

$hash = sha1( $ticket, true );

其他提示

$ticket = substr($decrypthex, 0, -20);
$hash = substr($decrypthex, -20);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top