Solved

MD5 Digest routine

Posted on 2004-09-24
4
337 Views
Last Modified: 2010-04-15
500 points to the guru that will help me finish that in time and provide me a routine that will take a string as input and will return me the 32 chars MD5 Digest generated by your routine (method or function)

Thanks a lot in advance !
0
Comment
Question by:pmengal
  • 2
4 Comments
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 12143647
If I understand what you are asking for this should do the trick...

using System.Security.Cryptography


public string EncryptString( string str ) {
   string rStr
   try {
     
      byte[] data = Encoding.Default.GetBytes(str);

      // This is one implementation of the abstract class MD5.
      MD5 md5 = new MD5CryptoServiceProvider();

      byte[] result = md5.ComputeHash(data);

      char[] chars = Encoding.Default.GetChars(result, 0, result.Length);
      rStr = new string(chars);

   } catch ( Exception ex ) {
      // do something with the exception!
   }
   return rStr;
}
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12143856
hashLength = 32;
                    data = Encoding.Default.GetBytes(text);
                    MD5 md5 = new MD5CryptoServiceProvider();
                    enc = md5.TransformFinalBlock(data, 0, data.Length);
                    foreach(byte b in md5.Hash)
                        hash += Convert.ToString(b, 16).ToUpper().PadLeft(2, '0');
                    md5.Clear();
0
 

Author Comment

by:pmengal
ID: 12144093
hashLength = 32;  is never used ? Normal ?

            public string GetMD5Digest(string input)
            {
                  int hashLength = 32;
                  string hash;
                  byte[] data = Encoding.Default.GetBytes(input);
                  MD5 md5 = new MD5CryptoServiceProvider();
                  byte[] enc = md5.TransformFinalBlock(data, 0, data.Length);
                  foreach(byte b in md5.Hash)
                        hash += Convert.ToString(b, 16).ToUpper().PadLeft(2, '0');
                  md5.Clear();
                  return hash;
            }
0
 
LVL 18

Accepted Solution

by:
armoghan earned 500 total points
ID: 12144400
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is "public object" in C#? 3 64
Keyboard 2 41
insert value of checklistbox checked 4 32
need to convert function to c# 5 26
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question