GitHub sha不一样
GitHub sha is different
如何计算与 GitHub 相同的哈希值?
我看到了答案,但结果还是不一样:
$file = "https://raw.githubusercontent.com/itm4n/Perfusion/master/Perfusion.sln"
$out = "D:\bu\Perfusion.sln"
$res = Iwr $file
$Content = "blob 2326\x00"+$res.Content
$Content|out-file $out
Get-FileHash -Algorithm SHA1 $out
输出:FCB24D664A2FB8D8F783A8D14C5087A276BC94E9
但是 here 我看到 c226191c92d0a7e43550f40f198ed96df9e65724
在可扩展字符串中使用转义序列 `0
来表达文字 NUL:
# download file
$file = "https://raw.githubusercontent.com/itm4n/Perfusion/master/Perfusion.sln"
$res = Invoke-WebRequest $file
# construct git blob
$encoding = [System.Text.Encoding]::UTF8
$content = $encoding.GetBytes($res.Content)
# here's that NUL byte
$blob = $encoding.GetBytes("blob $($content.Length)`0") + $content
# calculate sha1
$sha1 = [System.Security.Cryptography.SHA1Managed]::Create()
$hash = $sha1.ComputeHash($blob)
# print hash string
$hashString = [System.BitConverter]::ToString($hash).Replace('-','').ToLower()
Write-Host $hashString
这应该会产生正确的 blob 哈希
如何计算与 GitHub 相同的哈希值?
我看到了
$file = "https://raw.githubusercontent.com/itm4n/Perfusion/master/Perfusion.sln"
$out = "D:\bu\Perfusion.sln"
$res = Iwr $file
$Content = "blob 2326\x00"+$res.Content
$Content|out-file $out
Get-FileHash -Algorithm SHA1 $out
输出:FCB24D664A2FB8D8F783A8D14C5087A276BC94E9
但是 here 我看到 c226191c92d0a7e43550f40f198ed96df9e65724
在可扩展字符串中使用转义序列 `0
来表达文字 NUL:
# download file
$file = "https://raw.githubusercontent.com/itm4n/Perfusion/master/Perfusion.sln"
$res = Invoke-WebRequest $file
# construct git blob
$encoding = [System.Text.Encoding]::UTF8
$content = $encoding.GetBytes($res.Content)
# here's that NUL byte
$blob = $encoding.GetBytes("blob $($content.Length)`0") + $content
# calculate sha1
$sha1 = [System.Security.Cryptography.SHA1Managed]::Create()
$hash = $sha1.ComputeHash($blob)
# print hash string
$hashString = [System.BitConverter]::ToString($hash).Replace('-','').ToLower()
Write-Host $hashString
这应该会产生正确的 blob 哈希