By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

MD5 speedup

P: n/a
Hi group.

Any ideas how I could speed up/streamline the below code? Particuarly,
is there a way to use a progress bar for when it calculates the MD5?
Currently it just looks like it is hung for large files.
Private Function MakeMD5(srcFileName as String)

Dim DBfs As FileStream
Dim byt() As Byte

If (New FileInfo(srcFileName).Exists) Then

Try
Dim md5 As New MD5CryptoServiceProvider

DBfs = File.Open(srcFileName, FileMode.Open,
_FileAccess.Read, FileShare.ReadWrite)

byt = md5.ComputeHash(DBfs)

Return (BitConverter.ToString(byt))

Catch ex As Exception

Msgbox(ex.Message)

Finally '

If (Not IsNothing(DBfs)) Then DBfs.Close()

End Try

End If

End Function
--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Don
Since System.Security.Cryptography.MD5.ComputeHash() is doing all the work,
I don't think there's much more you can do.

However, System.Security.Cryptography.MD5.ComputeHash() also accepts a Byte
array. I doubt you would see any sort of performance increase by loading
the file into a byte array yourself and then passing that to ComputeHash(),
but it's something to try.

If you want to have a progress bar increment with this, then you'll have to
write a function that will compute the hash yourself. ComputeHash() doesn't
appear to raise any trappable progress events.

- Don

"Daniel" <da****@madridmadridsoleado.com> wrote in message
news:e$*************@TK2MSFTNGP15.phx.gbl...
Hi group.

Any ideas how I could speed up/streamline the below code? Particuarly,
is there a way to use a progress bar for when it calculates the MD5?
Currently it just looks like it is hung for large files.
Private Function MakeMD5(srcFileName as String)

Dim DBfs As FileStream
Dim byt() As Byte

If (New FileInfo(srcFileName).Exists) Then

Try
Dim md5 As New MD5CryptoServiceProvider

DBfs = File.Open(srcFileName, FileMode.Open,
_FileAccess.Read, FileShare.ReadWrite)

byt = md5.ComputeHash(DBfs)

Return (BitConverter.ToString(byt))

Catch ex As Exception

Msgbox(ex.Message)

Finally '

If (Not IsNothing(DBfs)) Then DBfs.Close()

End Try

End If

End Function
--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.

Nov 21 '05 #2

P: n/a
Don wrote:
Since System.Security.Cryptography.MD5.ComputeHash() is doing all the work,
I don't think there's much more you can do.

However, System.Security.Cryptography.MD5.ComputeHash() also accepts a Byte
array. I doubt you would see any sort of performance increase by loading
the file into a byte array yourself and then passing that to ComputeHash(),
but it's something to try.

If you want to have a progress bar increment with this, then you'll have to
write a function that will compute the hash yourself. ComputeHash() doesn't
appear to raise any trappable progress events.

- Don

"Daniel" <da****@madridmadridsoleado.com> wrote in message
news:e$*************@TK2MSFTNGP15.phx.gbl...
Hi group.

Any ideas how I could speed up/streamline the below code? Particuarly,
is there a way to use a progress bar for when it calculates the MD5?
Currently it just looks like it is hung for large files.
Private Function MakeMD5(srcFileName as String)

Dim DBfs As FileStream
Dim byt() As Byte

If (New FileInfo(srcFileName).Exists) Then

Try
Dim md5 As New MD5CryptoServiceProvider

DBfs = File.Open(srcFileName, FileMode.Open,
_FileAccess.Read, FileShare.ReadWrite)

byt = md5.ComputeHash(DBfs)

Return (BitConverter.ToString(byt))

Catch ex As Exception

Msgbox(ex.Message)

Finally '

If (Not IsNothing(DBfs)) Then DBfs.Close()

End Try

End If

End Function
--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.



I thought about doing it via a stream as this will at least allow me to
draw something on the screen. Any ideas how to do this?

Thanks.

--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.
Nov 21 '05 #3

P: n/a
Don

"Daniel" <da****@madridmadridsoleado.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
I thought about doing it via a stream as this will at least allow me to
draw something on the screen. Any ideas how to do this?


I've never done it, but I did a quick search and found an MD5 project here:

http://www.frez.co.uk/freecode.htm#md5

It's written in VB, but it should be easy to convert to VB.NET

- Don
Nov 21 '05 #4

P: n/a
since the idea is to show that something is happening and that the app
is not hung, you may want to consider an indeterminate progress bar.
microsoft published a c# sample for this here:
http://www.microsoft.com/downloads/d...displaylang=en

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.