Would you like to react to this message? Create an account in a few clicks or log in to continue.

    MD5 (Files & Processes)

    avatar
    Admin
    Admin


    Posts : 77
    Join date : 2009-07-28

    MD5 (Files & Processes) Empty MD5 (Files & Processes)

    Post  Admin Fri Aug 21, 2009 10:47 am

    public static string GetMD5HashFromFile(string fileName)
    {
    FileStream file = new FileInfo(fileName).OpenRead();
    MD5 md5 = new MD5CryptoServiceProvider();
    byte[] retVal = md5.ComputeHash(file);
    file.Close();

    ASCIIEncoding enc = new ASCIIEncoding();
    return enc.GetString(retVal);
    }
    avatar
    Admin
    Admin


    Posts : 77
    Join date : 2009-07-28

    MD5 (Files & Processes) Empty Re: MD5 (Files & Processes)

    Post  Admin Tue Oct 13, 2009 12:20 pm

    public static string getFilesMD5Hash(string filepath)
    {
    //MD5 hash provider for computing the hash of the file
    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

    //open the file
    FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read, 8192);

    //calculate the files hash
    md5.ComputeHash(stream);

    //close our stream
    stream.Close();

    //byte array of files hash
    byte[] hash = md5.Hash;

    //string builder to hold the results
    StringBuilder sb = new StringBuilder();

    //loop through each byte in the byte array
    foreach (byte b in hash)
    {
    //format each byte into the proper value and append
    //current value to return value
    sb.Append(string.Format("{0:X2}", b));
    }

    //return the MD5 hash of the file
    return sb.ToString();
    }
    avatar
    Admin
    Admin


    Posts : 77
    Join date : 2009-07-28

    MD5 (Files & Processes) Empty Re: MD5 (Files & Processes)

    Post  Admin Sun Jan 10, 2010 9:42 am

    Code:
    // SHA1 hash:
    string h1 = Convert.ToBase64String(new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes("one two")));

    // MD5 hash:
    string h2 = Convert.ToBase64String(new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes("one two")))

    Sponsored content


    MD5 (Files & Processes) Empty Re: MD5 (Files & Processes)

    Post  Sponsored content


      Current date/time is Mon May 20, 2024 11:26 am