c# - Folder Hash is returning different values every time -
c# - Folder Hash is returning different values every time -
for application using function hash whole folder. when running code in visual studio returning same hash value everytime folder created. after created .exe , tried same, returns different hash values each time run it. sure files within folder has no change. have attached code hashing function below. why happening?? new here , not sure if doing correctly, apologize if question isnt clear enough.
public static string createmd5forfolder(string path) { // assuming want include nested folders var files = directory.getfiles(path, "*.*", searchoption.alldirectories) .orderby(p => p).tolist(); md5 md5 = md5.create(); (int = 0; < files.count; i++) { string file = files[i]; // hash path string relativepath = file.substring(path.length + 1); byte[] pathbytes = encoding.utf8.getbytes(relativepath.tolower()); md5.transformblock(pathbytes, 0, pathbytes.length, pathbytes, 0); // hash contents byte[] contentbytes = file.readallbytes(file); if (i == files.count - 1) md5.transformfinalblock(contentbytes, 0, contentbytes.length); else md5.transformblock(contentbytes, 0, contentbytes.length, contentbytes, 0); } homecoming bitconverter.tostring(md5.hash).replace("-", "").tolower();
c# hash md5
Comments
Post a Comment