Solved

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

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

763 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