78f078ded4ae388e490c240c038c7f28

This is a simple example of Cryptography Class using MD5 algorithm.
Remember... the MD5 don't have "Decrypt" method... it's only by comparison!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private string getMD5String(string PlainText)
{
   System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
   byte[] inputBuffer = System.Text.Encoding.ASCII.GetBytes(PlainText);
   byte[] outputBuffer = md5.ComputeHash(inputBuffer); 

   //Convert the byte[] to a hex-string
   System.Text.StringBuilder builder = new System.Text.StringBuilder (outputBuffer.Length); 

   for (int i = 0; i < outputBuffer.Length; i++)
   {
      builder.Append(outputBuffer[i].ToString("X2"));
   } 

   return builder.ToString();
}

Refactorings

No refactoring yet !

D10ca8d11301c2f4993ac2279ce4b930

GoodDoer

September 2, 2008, September 02, 2008 03:10, permalink

No rating. Login to rate!

acidmind, you do know that this is a place where people post code snippets for others to refactor, right?
there are a few code-snippet-repositories where you can submit your code (if you feel you have to...)

89577e80c2e342f49e5c007097e77218

mvwxpe

September 10, 2008, September 10, 2008 20:30, permalink

No rating. Login to rate!

mrkaobovvigoccqxdbiqwzycuvitoo

4cb16198f4021215b6fc7de12b1e249b

David

October 19, 2008, October 19, 2008 09:20, permalink

No rating. Login to rate!

refactored using linq syntax, removing unnecessary variables

1
2
3
4
private string CreateMD5String(string s) {
            byte[] hashedBytes = MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(s));
            return String.Join(String.Empty, hashedBytes.Select(b => b.ToString("x2")).ToArray());
        }

Your refactoring





Format Copy from initial code

or Cancel