Click here to Skip to main content
Click here to Skip to main content

MD5 and SHA-1 Hashing (for String and Files)

, 2 Mar 2006
Rate this:
Please Sign up or sign in to vote.
MD5 and SHA-1 Hashing for String and Files using the .NET cryptography Provider

Introduction

This Page deals provides an Example code to show how to implement the .NET MD5 and SHA-1 cryptography Class.

In order to use the MD5 or SHA-1 Class that .NET provides, u must realize that it accepts and returns byte arrays only.

public byte[] ComputeHash ( byte[] buffer , System.Int32 offset , System.Int32 count )
//or public byte[] ComputeHash ( byte[] buffer)
//buffer is the string represented in bytes

this means that u have to convert the string to a byte array, send it to the function and prepare to convert the result byte array back to string.

this was done using this code i found here on code project:

public string encryptString(byte[] RawStringBytes)
{
    /// <summary>
    /// converts the MD5 of SHA-1 result byte[] to a string 
representative
    /// </summary>
    string hashString ="";
    for(int i=0;i<RawStringBytes.Length;i++)
    {
        hashString += Convert.ToString(RawStringBytes[i], 16).PadLeft(2,'0');
    }
    return hashString.PadLeft(32,'0');
}

just download and examine the c# coding for more details on how it works.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

donperry
Web Developer
United States United States
Ayson Baxter Bsc.
 
born 1984, this young Jamaican programmer is enthused by Network programming and security.
 

Comments and Discussions

 
QuestionHow to compare 2 md5 strings PinmemberVikas Gandhi12-Jul-07 23:36 
AnswerRe: How to compare 2 md5 strings Pinmemberdonperry13-Jul-07 5:17 
QuestionMD5 to String Pinmemberangelboy24-Feb-07 7:41 
AnswerRe: MD5 to String Pinmemberdonperry25-Feb-07 8:36 
GeneralRe: MD5 to String Pinmemberangelboy25-Feb-07 9:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150129.1 | Last Updated 2 Mar 2006
Article Copyright 2006 by donperry
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid