MD5 Encrypt - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:AES

Description

MD5 Encrypt

Demo Code


using System.Text;
using System.Security.Cryptography;
using System;// w  w  w  . ja v  a  2 s  . c  o  m

public class Main{

        public static string MD5Encrypt(string input)
        {
            // step 1, calculate MD5 hash from input
            MD5 md5 = MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);
            // step 2, convert byte array to hex string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString();
        }
}

Related Tutorials