12.9.05

Simple MD5 hash

I made a simple MD5 hasher today, I needed to check some hashes so I thought this might be handy.

The code is extremely simple, so here it is:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Security.Cryptography;
using System.Text;

namespace hasher
{
///
/// Summary description for Form1.
///

public class hash : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txt_data;
private System.Windows.Forms.Label lbl_hash;
private System.Windows.Forms.GroupBox grp_hash;

private MD5 md5;
private UTF8Encoding ue;

///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public hash()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

md5 = new MD5CryptoServiceProvider();
ue = new System.Text.UTF8Encoding();
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.txt_data = new System.Windows.Forms.TextBox();
this.lbl_hash = new System.Windows.Forms.Label();
this.grp_hash = new System.Windows.Forms.GroupBox();
this.grp_hash.SuspendLayout();
this.SuspendLayout();
//
// txt_data
//
this.txt_data.Location = new System.Drawing.Point(8, 8);
this.txt_data.Multiline = true;
this.txt_data.Name = "txt_data";
this.txt_data.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txt_data.Size = new System.Drawing.Size(272, 112);
this.txt_data.TabIndex = 0;
this.txt_data.Text = "";
this.txt_data.TextChanged += new System.EventHandler(this.txt_data_TextChanged);
//
// lbl_hash
//
this.lbl_hash.Location = new System.Drawing.Point(8, 16);
this.lbl_hash.Name = "lbl_hash";
this.lbl_hash.Size = new System.Drawing.Size(256, 23);
this.lbl_hash.TabIndex = 1;
//
// grp_hash
//
this.grp_hash.Controls.Add(this.lbl_hash);
this.grp_hash.Location = new System.Drawing.Point(8, 128);
this.grp_hash.Name = "grp_hash";
this.grp_hash.Size = new System.Drawing.Size(272, 40);
this.grp_hash.TabIndex = 2;
this.grp_hash.TabStop = false;
this.grp_hash.Text = "MD5";
//
// hash
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 173);
this.Controls.Add(this.grp_hash);
this.Controls.Add(this.txt_data);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "hash";
this.Text = "MD5 Hasher";
this.grp_hash.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new hash());
}

private void txt_data_TextChanged(object sender, System.EventArgs e)
{
byte[] b = ue.GetBytes(txt_data.Text);
lbl_hash.Text = Convert.ToBase64String(md5.ComputeHash(b));
}
}
}

4 comments:

Anonymous said...

Read this: http://www.darksideprogramming.org/archives/2005/09/md5_exploit.html

prodactors head said...

Ok

prodactors head said...

ohh, I read it - way cool!

CloCkWeRX said...

*hits you with one-true-brace*