I'm trying to compute an MD5 hash using an HttpPostedFile's InputStream.
There aren't any issues creating the hash or converting the hash. However, the hash is the same, no matter what file I upload (using ASP FileUpload control).
I saw a solution involving setting the Stream.Position = 0 before ComputeHash, but it is still the same.
Is HttpPostedFile.InputStream always going to create the same MD5 hash or is there something I am missing in my code?
I'd appreciate any suggestions. Thanks in advance.
private static string GetMd5FileHash(HttpPostedFile file)
{
using (var md5 = MD5.Create())
{
file.InputStream.Position = 0;
var hash = md5.ComputeHash(file.InputStream);
return Convert.ToBase64String(hash);
}
}
UPDATE:
Just discovered that the MD5 hash I've been receiving is generic, which probably means it's not reading the InputStream.