HighTechTalks DotNet Forums  

MD5 function in VB vs MD5 function in Linux

Dotnet Scripting microsoft.public.dotnet.scripting


Discuss MD5 function in VB vs MD5 function in Linux in the Dotnet Scripting forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Dirty Sanchez
 
Posts: n/a

Default MD5 function in VB vs MD5 function in Linux - 09-16-2004 , 06:57 PM






In using the following syntax for a web page to demonstrate MD5 using VB, I noticed that the output is not the same as the md5 output you get from the command line in linux. Any tips on how I can get them to match up?

Example

md5 -dpassword yields: 5F4DCC3B5AA765D61D8327DEB882CF99
when I enter "password" on the following form I get: sIHb6F4ew//D1OfQInQAzQ

Perhaps it has something to do with the base 64 conversion below?

<%@ Import Namespace="System"%>
<%@ Import Namespace="System.Text"%>
<%@ Import Namespace="System.Security.Cryptography" %>
<script runat="server" language="VB">
Sub Page_Load(sender as Object, e as EventArgs)
If IsPostBack Then
Dim HashValue as Byte()
Dim UE As New UnicodeEncoding()

Dim MessageBytes As Byte() = UE.GetBytes(txtStuff.Text)

Dim Md5 As New MD5CryptoServiceProvider()
HashValue = MD5.ComputeHash(MessageBytes)
Dim theValue = Convert.ToBase64String(HashValue)
Response.Write(theValue.Replace("==",""))

End If


End Sub
</script>

<form runat="server">
<h1>Enter text to be hashed:</h1>
<br>
<asp:TextBox runat="server" id="txtStuff" />
<p><asp:Button runat="server" Text="Encrypt Text" /></p>
</form>

___
Newsgroups brought to you courtesy of www.dotnetjohn.com

Reply With Quote
  #2  
Old   
cdware
 
Posts: n/a

Default RE: MD5 function in VB vs MD5 function in Linux - 01-17-2005 , 06:33 PM







I believe your problem is that your using Unicode (2 byte). Try
UTF8Encoding instead.
A quick test is try MD5 (""). The resuld should be
"d41d8cd98f00b204e9800998ecf8427e" on your VB code and Linux.



"Dirty Sanchez" wrote:

Quote:
In using the following syntax for a web page to demonstrate MD5 using VB, I noticed that the output is not the same as the md5 output you get from the command line in linux. Any tips on how I can get them to match up?

Example

md5 -dpassword yields: 5F4DCC3B5AA765D61D8327DEB882CF99
when I enter "password" on the following form I get: sIHb6F4ew//D1OfQInQAzQ

Perhaps it has something to do with the base 64 conversion below?

%@ Import Namespace="System"%
%@ Import Namespace="System.Text"%
%@ Import Namespace="System.Security.Cryptography" %
script runat="server" language="VB"
Sub Page_Load(sender as Object, e as EventArgs)
If IsPostBack Then
Dim HashValue as Byte()
Dim UE As New UnicodeEncoding()

Dim MessageBytes As Byte() = UE.GetBytes(txtStuff.Text)

Dim Md5 As New MD5CryptoServiceProvider()
HashValue = MD5.ComputeHash(MessageBytes)
Dim theValue = Convert.ToBase64String(HashValue)
Response.Write(theValue.Replace("==",""))

End If


End Sub
/script

form runat="server"
h1>Enter text to be hashed:</h1
br
asp:TextBox runat="server" id="txtStuff" /
p><asp:Button runat="server" Text="Encrypt Text" /></p
/form

___
Newsgroups brought to you courtesy of www.dotnetjohn.com


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.