Solved

MD5 Digest routine

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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