Convert hashed password to 128-bit binary

G

Guest

Hello,

I am using hashpasswordforstoringinconfigfile with md5 to generate a
32-character hashed password. But, since that string is only hex characters
and is really only 128 bits (16 bytes), I'd like to shrink it down to that
size and store as a 'binary' in the database. My goal is to cut down what I'm
storing without losing info. I'm guessing there is a simple conversion
function to take this hex string down to a byte array, but I'm not seeing it.
Any thoughts?

Thanks,

Bill
 
M

Matt Berther

Hello Bill,

Encoding.UTF8.GetBytes(string) should do what you're after. You might also
be able to glean some more information from an article I posted [1] on my
website that discusses how to create a FormsAuthentication compatible MD5
hash without using the FormsAuthentication methods.

[1] http://www.mattberther.com/2005/03/000608.html
 
G

Guest

Matt, thanks. The encoding got me the array of bytes, but still 32 long, and
what I really want is to squeeze each pair into a single byte, since I know
each one only needs four bits. Going back to the raw computehash function is
interesting, but still doesn't help. Probably an easier way somewhere, but
what I ended up doing was this (p32 is the 32-byte string as returned from
the md5 hash):

Private Const hexString As String = "0123456789ABCDEF"

Dim sb As New System.Text.StringBuilder
Dim intValue As Integer
Dim c() As Char = p32.ToCharArray
For i As Integer = 0 To c.Length - 1 Step 2
intValue = hexString.IndexOf(c(i))
intValue += (hexString.IndexOf(c(i + 1)) * 16)
sb.Append(Chr(intValue))
Next
Return sb.ToString


Bill

Matt Berther said:
Hello Bill,

Encoding.UTF8.GetBytes(string) should do what you're after. You might also
be able to glean some more information from an article I posted [1] on my
website that discusses how to create a FormsAuthentication compatible MD5
hash without using the FormsAuthentication methods.

[1] http://www.mattberther.com/2005/03/000608.html

--
Matt Berther
http://www.mattberther.com
Hello,

I am using hashpasswordforstoringinconfigfile with md5 to generate a
32-character hashed password. But, since that string is only hex
characters and is really only 128 bits (16 bytes), I'd like to shrink
it down to that size and store as a 'binary' in the database. My goal
is to cut down what I'm storing without losing info. I'm guessing
there is a simple conversion function to take this hex string down to
a byte array, but I'm not seeing it. Any thoughts?

Thanks,

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top