Get Md5 Hash - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:MD5

Description

Get Md5 Hash

Demo Code


using System.Web;
using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.Collections.Generic;
using System;/* ww w  . java 2s .  c  o m*/

public class Main{
        public static string GetMd5Hash(string input)
        {
            MD5 md5Hasher = MD5.Create();

            byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
            StringBuilder sBuilder = new StringBuilder();

            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            return sBuilder.ToString();
        }
}

Related Tutorials