Exemple de cryptage des phrase avec MD*

Author:

Exemple,d'utilisation,de,'PermissionSet'
{filelink=17844}

//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 CryptageMD5
  {
    public static string CrypterEnMD5 ( 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();
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *