473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

MD5 HASH Encoding Problem

This function doesn't seem to be giving me the appearance I expect. This
should appear more like
"1ba442ab45c8002a86d068d1c1748e44" but it looks really cryptic and screwy,
like "*óìØLÜzrVÊ%' \Y7".

Here is my code segment written in VB.NET Enterprise Architect:
--------
Public Function MD5File(ByVal Filename As String) As String
'
' Read a file, produce an MD5 hashed key value in a String.
'
With New Security.Cryptography.MD5CryptoServiceProvider
Dim result() As Byte = .ComputeHash( New
IO.StreamReader(Filename).BaseStream )
Dim Encoding As Text.Encoding = System.Text.Encoding.Default
Return Encoding.GetString(result)
Encoding = Nothing
.Clear()
End With
End Function
---------
Perhaps you can suggest a modification to my code which yields a more
hex-like string. I'm new to VB.NET, but I love it so far.
Thanks,
~ Shaun
near Seattle, WA

Nov 21 '05 #1
2 4448
Nak
Hi there,

This is much easier done by loading the file into a byte array first,

Imports System.Security.Cryptography

Public Function createHash(ByVal iByteArray() As Byte) As String
Dim pBytHash() As Byte
pBytHash = New MD5CryptoServiceProvider().ComputeHash(iByteArray)
Return (BitConverter.ToString(pBytHash, 0, pBytHash.GetUpperBound(0)))
End Function

You can then use the above function to get an MD5 Hash of the data.

Nick.

"Shaun Merrill" <sm*******@comcast.net> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
This function doesn't seem to be giving me the appearance I expect. This
should appear more like
"1ba442ab45c8002a86d068d1c1748e44" but it looks really cryptic and screwy,
like "*óìØLÜzrVÊ%' \Y7".

Here is my code segment written in VB.NET Enterprise Architect:
--------
Public Function MD5File(ByVal Filename As String) As String
'
' Read a file, produce an MD5 hashed key value in a String.
'
With New Security.Cryptography.MD5CryptoServiceProvider
Dim result() As Byte = .ComputeHash( New
IO.StreamReader(Filename).BaseStream )
Dim Encoding As Text.Encoding = System.Text.Encoding.Default
Return Encoding.GetString(result)
Encoding = Nothing
.Clear()
End With
End Function
---------
Perhaps you can suggest a modification to my code which yields a more
hex-like string. I'm new to VB.NET, but I love it so far.
Thanks,
~ Shaun
near Seattle, WA

Nov 21 '05 #2
Shaun,

The result you are getting is actually correct... it's just not formatted in
"nice-hex-format", you still have it as raw data.

Here's a quick code snippet that will take your raw data, and display it how
you want...

///
Dim strMD5 As String
For Each bytByte As Byte In result
strMD5 &= bytByte.ToString("x2")
Next
///

Now, strMD5 contains the nicely formatted MD5 hash. (Assuming 'result' is
your byte array).

Also, you have an unreachable code segment in your code:
Encoding = Nothing
.Clear()
These two lines will *never* be called, because they are preceeded with a
'Return' statement, which exits the method.

Hope this helps!

-- Tom Spink

"Shaun Merrill" wrote:
This function doesn't seem to be giving me the appearance I expect. This
should appear more like
"1ba442ab45c8002a86d068d1c1748e44" but it looks really cryptic and screwy,
like "Â*óìØLÃœzrVÊ%' \Y7".

Here is my code segment written in VB.NET Enterprise Architect:
--------
Public Function MD5File(ByVal Filename As String) As String
'
' Read a file, produce an MD5 hashed key value in a String.
'
With New Security.Cryptography.MD5CryptoServiceProvider
Dim result() As Byte = .ComputeHash( New
IO.StreamReader(Filename).BaseStream )
Dim Encoding As Text.Encoding = System.Text.Encoding.Default
Return Encoding.GetString(result)
Encoding = Nothing
.Clear()
End With
End Function
---------
Perhaps you can suggest a modification to my code which yields a more
hex-like string. I'm new to VB.NET, but I love it so far.
Thanks,
~ Shaun
near Seattle, WA

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bill Burwell | last post by:
I am converting a VB6 WebClass application to VB.Net. Used the VB upgrade tool to do the conversion - and it left me a lot of little code things to do. Did those code things and got my app to...
0
by: Bshowers | last post by:
I need to generate an MD5 hash in ASP, not ASP.NET, and have that hash be the same as what is produced by the .NET MD5CryptoServiceProvider. This is the vb.net code I am using... Function...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
4
by: flipdog | last post by:
Hello all, I didn't know there is a thread on hash function started in this newsgroup so reposted my posting from another group. Hope I can have some feedbacks. I am new to hash table. I came...
2
by: Phil Townsend | last post by:
I have been asked to rewrite some apps that contain databases of username and passwords to store the passwords as hashes. Getting the data into a hash format is no problem. however, how do I go...
3
by: John M | last post by:
Hello, Something quire is on my application. If I don't touch the computer for about 30 minutes, I get the message (something like) hash.exe is not accesible due security .... Any idea. ...
1
by: c676228 | last post by:
Hi, I have met this problem for many times, I don't how to fix it, the only thing I can do is to restart the computer. Here is the case: Sometimes when I change the behide class code, and then...
2
by: johnnyG | last post by:
Greetings, I'm studying for the 70-330 Exam using the MS Press book by Tony Northrup and there are 2 side-by-side examples of using the SHA1CryptoServiceProvider to create a hash value from a...
5
by: andrewcw | last post by:
I have a VB 5 module that duplicates the FCIV.exe from Microsoft. I need to move an application forward to C#, but the samples for MD5 hash using the framework I tried gave different hashes. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.