Solved

MD5 Digest routine

Posted on 2004-09-24
4
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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

735 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