NinethSense oWnZ mE!: Praveen’s drawing book

Choose a Topic:

Thu
12
Jul '07

MD5 with t-sql

You can use HashBytes to achieve.
Check this for reference: http://msdn2.microsoft.com/en-us/library/ms174415.aspx

SELECT 
	HashBytes(‘MD5′, ‘Praveen’),
	HashBytes(‘MD5′, ‘PraveeN’),
	‘0xD09C2ECC3DFCDC8C8D921B589097FCB1′,
 
	CASE WHEN convert(int,HashBytes(‘MD5′, ‘PraveeN’)) = 0xD09C2ECC3DFCDC8C8D921B589097FCB1 
	THEN 
		‘Success’ 
	ELSE
		‘Failed’
	END


Note: for MySQL you have MD5() function
'

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();
        }
    }
}
The CodeProject Microsoft Developer Network Official ASP.NET Forums Microsoft .NET Framework Community Microsoft Most Valuable Professional Kidoos forums Microsoft Visual Studio Developer Home Professional Information Technology Solutions Microsoft Research Home Kerala Microsoft Users Group Community Website