some filestream. Something weird is that the hash computed after the first one is erroneous which makes me wonder whether the FileStream object is being disposed. Below is my sample code. Could anyone provide some pointers? I am trying my best to avoid re-reading the file everytime I want to compute a different hash. Thanks
private string[] Hashes(FileStream stream)
{
string md5 = Md5(stream);//output is correct
string sha1 = Sha1(stream);//output is invalid
return new string[] { md5, sha1};
}
private string Md5(FileStream stream)
{
using (MD5 md5 = MD5.Create())
{
return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", String.Empty).ToLower();
}
}
private string Sha1(FileStream stream)
{
using (SHA1 sha1 = SHA1.Create())
{
return BitConverter.ToString(sha1.ComputeHash(stream)).Replace("-", String.Empty).ToLower(); ;
}
}
Do u want take hash with hexbase output ?
Обсуждают сегодня