Get md5 string for a String - CSharp Security

CSharp examples for Security:MD5

Description

Get md5 string for a String

Demo Code


using System.Text;
using System.IO;// w  w w  . j a va 2  s  .  c  om
using System;

public class Main{
        /// <summary>  
        /// Get md5 string for a String  
        /// </summary>  
        /// <param name="value">Source String</param>  
        /// <returns>md5 string</returns>  
        public static string GetMD5ForString(string value)
        {
            string md5String = string.Empty;
            if (value != string.Empty)
            {
                System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
                md5String = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(value))).Replace("-", string.Empty);                
            }

            return md5String;
        }
}

Related Tutorials