rickyzhang2008
Member
- Apr 16, 2018
- 10
When using the C# code below to compute SHA256 for the same file named "browser.dll" in two different path, but the sha256 value are different, why?
the same file: "browser.dll",
first full path: "C:\Windows\System32\browser.dll",
second full path: "E:\xiufu\browser.dll".
important thing:
"browser.dll" in second full path was copied from the first full path "C:\Windows\System32\browser.dll", but their sha256 value are different totally.
the sha256 value of "C:\Windows\System32\browser.dll" : "QAEROIafVJaj5404yZALRmtvOHdSasIpUtzVKBc/RkU=",
the sha256 value of "E:\xiufu\browser.dll": "nMJfH5P6ym9s4j9461hZDDmi48ijrN9ADoqd4HV+ra4=".
so what happened to the file "browser.dll"? please help,thanks.
the same file: "browser.dll",
first full path: "C:\Windows\System32\browser.dll",
second full path: "E:\xiufu\browser.dll".
important thing:
"browser.dll" in second full path was copied from the first full path "C:\Windows\System32\browser.dll", but their sha256 value are different totally.
the sha256 value of "C:\Windows\System32\browser.dll" : "QAEROIafVJaj5404yZALRmtvOHdSasIpUtzVKBc/RkU=",
the sha256 value of "E:\xiufu\browser.dll": "nMJfH5P6ym9s4j9461hZDDmi48ijrN9ADoqd4HV+ra4=".
so what happened to the file "browser.dll"? please help,thanks.
C#:
using (SHA256 sha256 = SHA256.Create())
{
try
{
string fileFullPath = @"C:\Windows\System32\browser.dll";//@"E:\xiufu\browser.dll";
string combineHsh = "nMJfH5P6ym9s4j9461hZDDmi48ijrN9ADoqd4HV+ra4=||QAEROIafVJaj5404yZALRmtvOHdSasIpUtzVKBc/RkU=";
using (FileStream fileStream = File.Open(fileFullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
string[] hssArr = combineHsh.Split(new string[] { "||" }, 2, StringSplitOptions.None);
try
{
// Create a fileStream for the file.
// Be sure it's positioned to the beginning of the stream.
fileStream.Position = 0;
// Compute the hash of the fileStream.
byte[] hashValue = sha256.ComputeHash(fileStream);
string sha256Base64Str = Convert.ToBase64String(hashValue);
if (sha256Base64Str.CompareTo(hssArr[1]) == 0)
{
bEqual = true;
}
else
{
bEqual = false;
}
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("Hash compare:" + e.Message);
}
}
}
catch (IOException e)
{
Console.WriteLine("Open file for hash:" + e.Message);
}
catch (UnauthorizedAccessException e)
{
Console.WriteLine("Open file for hash:" + e.Message);
}
}