Solved

MD5 Digest routine

Posted on 2004-09-24
4
334 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now