I've been looking for a lot, it works, and I have time to study it.
Public static String Getmd5hash (String fileName)
{
Try
{
FileStream file = new FileStream (FileName, FileMode.Open);
System.Security.Cryptography.MD5 MD5 = new System.Security.Cryptography.MD5CryptoServiceProvider ();
byte[] RetVal = md5.computehash (file);
file. Close ();
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < retval.length; i++)
{
sb. Append (Retval[i]. ToString ("X2"));
}
return SB. ToString ();
}
catch (Exception ex)
{
throw new Exception ("Getmd5hash () Fail,error:" + ex. Message);
}
}
public static string Getmd5hash (byte[] bytedata)
{
Try
{
System.Security.Cryptography.MD5 MD5 = new System.Security.Cryptography.MD5CryptoServiceProvider ();
byte[] RetVal = Md5.computehash (bytedata);
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < retval.length; i++)
{
Sb. Append (Retval[i]. ToString ("X2"));
}
Return SB. ToString ();
}
catch (Exception ex)
{
throw new Exception ("Getmd5hash () Fail,error:" + ex. Message);
}
}
Source URL:
http://blog.csdn.net/snakorse/article/details/19578519
C # get File/byte array MD5 value method