Solved

MD5 Digest routine

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

27 Experts available now in Live!

Get 1:1 Help Now