Solved

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

Posted on 2007-04-04
3
183 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

867 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

16 Experts available now in Live!

Get 1:1 Help Now