Solved

How to store 128 bit hash values optimaly in MS Access using ASP.NET

Posted on 2007-04-04
3
182 Views
Last Modified: 2012-05-05
I need to store the result of MD5 hashing to a database (MS Access) and currently the best option I understand is to convert it to a string and save that.  Is there a cleaner way of saving this data?

I start out with the value of hash1 from the following which produces an array of bytes (128 bit)

Dim MyHasher As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim file1 As New FileStream("d:/customer/remcontshop/temp/upload.pdf", FileMode.Open)
Dim hash1 As Byte() = MyHasher.ComputeHash(file1)
file1.Close()
lblResult.Text = BitConverter.ToString( hash1 )

The value calculated for lblResult gives me the hash as a 16 bit hex string seperated by hyphens e.g.
"57-D9-95-B8-6F-23-CD-DB-78-E4-A1-10-24-BE-3C-C1"
I can store this to my database as text but if I can do it in a more efficient way, I'd prefer that.

Ideally I want it in a form where I can query it easily with SQL.  e.g.
SELECT * FROM hash_table WHERE hashvalue = "57-D9-95-B8-6F-23-CD-DB-78-E4-A1-10-24-BE-3C-C1"

Any ideas on how to get a more efficient result?
0
Comment
Question by:Beamson
3 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18849753
1) I would remove the dashes, since they are not needed, and only increase the size of your database.

2) There are ways to store the byte array in SQL Server, instead of the string.  This example writes an image to a BLOB:

Conserving Resources When Writing BLOB Values to SQL Server  
http://msdn2.microsoft.com/en-us/library/3517w44b.aspx

Here is another example that shows getting a byte array of data and writing to SQL Server:

Writing BLOB Values to a Data Source  
http://msdn2.microsoft.com/en-us/library/4f5s1we0.aspx

Bob
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 125 total points
ID: 18850085
Well since you already have Hexadecimal pairs, there is no reason you could not store them in a 16 byte string that way.

JimD
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now