[Solved] Get the MD5 hash code (as a String) for a given file in C# [closed]


You’ve forgot to state the correct question. As I can see from the Java code provided (reverse engineering), all you want is to have MD5 hash code (as a String) for a given file; if it’s your case, you want just to

  1. Create MD5 crypto
  2. Open the file
  3. Compute hash on file stream
  4. Represent hash (which is Byte[]) as String.

The implementation could be

using System.IO;
using System.Security.Cryptography;
...
//TODO: it's very time to rename "sig" into something more readable
private static String sig(String fileName) {
  using (MD5 md5Hash = MD5.Create()) {
    using (FileStream stm = new FileStream(fileName, FileMode.Open)) {
      return String.Concat(md5Hash
        .ComputeHash(stm)
        .Select(b => b.ToString("X2")));
    }
  }
}

2

solved Get the MD5 hash code (as a String) for a given file in C# [closed]