MD5 Hash - CSharp Security

CSharp examples for Security:MD5

Description

MD5 Hash

Demo Code


using System.Web;
using System.Linq;
using System.Collections.Generic;
using System;/*from w  w w  .  j a  v a 2s. co  m*/

public class Main{
        public static string Hash(string input)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString();
        }
}

Related Tutorials