Post: C# Generating MD5's ,return it as a string
08-11-2013, 06:05 AM #1
Default Avatar
Oneup
Guest
(adsbygoogle = window.adsbygoogle || []).push({});
    using System.Text;

using System.Windows.Forms;

using System.Security.Cryptography;

namespace CSharpMD5Hashing

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void btn_Hash_Click(object sender, EventArgs e)

{

MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();

byte[] hashedPassword;

UTF8Encoding encoder= new UTF8Encoding();

StringBuilder HashString = new System.Text.StringBuilder();

hashedPassword = md5Hasher.ComputeHash(encoder.GetBytes(txt_TextToHash.Text));

foreach (byte b in hashedPassword)

{

HashString.Append(b.ToString("x2"));

}

txt_HashedText.Text = Convert.ToString(HashString);

}

}

}


You must login or register to view this content.
08-11-2013, 08:36 AM #2
Pichu
RIP PICHU.
Originally posted by UP View Post
    using System.Text;

using System.Windows.Forms;

using System.Security.Cryptography;

namespace CSharpMD5Hashing

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void btn_Hash_Click(object sender, EventArgs e)

{

MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();

byte[] hashedPassword;

UTF8Encoding encoder= new UTF8Encoding();

StringBuilder HashString = new System.Text.StringBuilder();

hashedPassword = md5Hasher.ComputeHash(encoder.GetBytes(txt_TextToHash.Text));

foreach (byte b in hashedPassword)

{

HashString.Append(b.ToString("x2"));

}

txt_HashedText.Text = Convert.ToString(HashString);

}

}

}


You must login or register to view this content.


Use instead:

string hash = "":
hash = BitConverter.ToString(md5.computerHash(utf8.getBytes("string")));

It will return the string value of the md5 hash and is the traditional way to do it in Microsoft C#.

The following user thanked Pichu for this useful post:

08-11-2013, 08:49 AM #3
Default Avatar
Oneup
Guest
Originally posted by Pichu View Post
Use instead:

string hash = "":
hash = BitConverter.ToString(md5.computerHash(utf8.getBytes("string")));

It will return the string value of the md5 hash and is the traditional way to do it in Microsoft C#.


Didn't even think of that. Thanks for the input

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo