MD5 Encrypt : MD5 « Security « C# / C Sharp






MD5 Encrypt

  

//http://activedeveloperdk.codeplex.com/
//The MIT License (MIT)

using System;
using System.Security.Cryptography;
using System.Security;
using System.IO;
using System.Text;

namespace ActiveDeveloper.Core.Utilities
{
  public class Encryption
  {
    public static string MD5Encrypt ( string phrase )
    {
      UTF8Encoding encoder = new UTF8Encoding();
      MD5CryptoServiceProvider md5hasher = new MD5CryptoServiceProvider();
      byte[] hashedDataBytes = md5hasher.ComputeHash( encoder.GetBytes( phrase ) );

      return byteArrayToString( hashedDataBytes );
    }

    private static string byteArrayToString ( byte[] inputArray ) 
    { 
      StringBuilder output = new StringBuilder( "" ); 
      
      for ( int i = 0; i < inputArray.Length; i++ ) { 
        output.Append( inputArray[i].ToString( "X2" ) );
      } 
      
      return output.ToString(); 
    }
  }
}

   
    
  








Related examples in the same category

1.MD5 encode
2.Create MD5 Hash
3.Create ASCII MD5 Hash
4.Encrypt MD5
5.MD5 Hash
6.MD5 Hash
7.Get MD5 Hash
8.Makes a MD5 hash from a string
9.Get MD5 Hash (2)
10.Computes the MD5 checksum for a single file.
11.Get MD5 for a string
12.Get and verify MD5 Hash
13.Md5 Hash (2)