Solved

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

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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