MD5 Hash String - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:MD5

Description

MD5 Hash String

Demo Code


using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.Collections.Generic;
using System;//from   w  w  w . j a  v a  2s.  c  om

public class Main{
        public static string MD5Hash(string text)
        {
            byte[] hash = Encoding.ASCII.GetBytes(text);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] hashenc = md5.ComputeHash(hash);
            string result = "";
            foreach (var b in hashenc)
            {
                result += b.ToString("x2");
            }
            return result;
        }
}

Related Tutorials