get MD5 String for a String - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:MD5

Description

get MD5 String for a String

Demo Code


using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.Collections.Generic;
using System;/*w ww .j  a  v a 2  s  .  c o  m*/

public class Main{

        public static string getMD5String(string str)
        {
            MD5 md5 = MD5.Create();
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
            byte[] md5byte = md5.ComputeHash(bytes);
            md5.Clear();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < md5byte.Length; i++)
            {
                sb.Append(md5byte[i].ToString("x2"));
            }
            return sb.ToString();
        }
}

Related Tutorials