C# simple MD5 encryption

Now this is the easiest way to MD5 password :

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Security.Cryptography;
  5.  
  6. namespace Net.MedSo.Mooci.Security
  7. {
  8.     public class MD5Encryption : IEncryption
  9.     {
  10.  
  11.         private static MD5Encryption md5Encryption;
  12.  
  13.         // Factory pattern to return only a single
  14.         // instance of MD5Encryption in the application
  15.         public static MD5Encryption GetInstance(){
  16.             if(md5Encryption == null){
  17.                 return new MD5Encryption();
  18.             }
  19.  
  20.             return md5Encryption;
  21.         }
  22.        
  23.         // Default constructor
  24.         public MD5Encryption() {
  25.         }
  26.  
  27.         /*
  28.          * Return the encrypted string
  29.          */
  30.         public string GetEncryptedString(string strToEncrypt) {
  31.  
  32.             MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
  33.             byte[] data = Encoding.ASCII.GetBytes(strToEncrypt);
  34.             data = provider.ComputeHash(data);
  35.  
  36.             return Encoding.ASCII.GetString(data);
  37.         }
  38.     }
  39. }

Hope this useful.
Thank’s :)

Related Articles

Leave a Reply