Solved

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

Posted on 2007-04-04
3
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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