MD5 encryption with c#
This code shows how to encrypt a string with MD5 algorithm:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Text;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Text = getMD5("test");
}
private string getMD5(String str)
{
MD5CryptoServiceProvider mdcsp = new MD5CryptoServiceProvider();
byte[] b = System.Text.Encoding.UTF8.GetBytes(str);
b = mdcsp.ComputeHash(b);
StringBuilder s = new StringBuilder();
foreach (byte by in b)
{
s.Append(by.ToString(”x2″).ToLower());
}
return s.ToString();
}
}
}
Related posts:






















