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();
}
}
}

VN:F [1.1.6_502]
Rating: 2.0/5 (1 vote cast)
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • DotNetKicks
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati

Related posts:

  1. Find your lucky number in c#
  2. UTF7 Converter
  3. System.IO.Compression.GZipStream
  4. C# Multiple Watermarking in same image
  5. How to dynamically make an InfoPath form