473,465 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convert hashed password to 128-bit binary

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
Nov 19 '05 #1
4 2604
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

Nov 19 '05 #2
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

Nov 19 '05 #3
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" wrote:
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


Nov 19 '05 #4
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" wrote:
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


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robert Zierhofer | last post by:
hi there, it seems as if i cant convert the euro and pound sign to their html equivalents. i tried eregi_replace("", "€", $haystack); eregi_replace("", "£", $haystack); as...
2
by: jj | last post by:
Howo do you convert this vb to c#? Asc and Mid functions are not in c#. any help is appreciated. If Asc(Mid$(Text, i, 1)) < 128 Then strTempChar = CType(Asc(Mid$(Text, i, 1)) - 49, String) ...
4
by: Terry Miller | last post by:
I have DB2 V8.2 loaded on a Redhat Enterprise Linux version 3 (RHEL 3) box. RHEL is configured to talk to LDAP for authenticaton besides the local passwd file. I can verify this by executing an su...
7
by: P. Adhia | last post by:
Hi, I don't have much experience writting UDFs, so I don't know if this is possible (and simple). I am basically looking to write a wrapper table UDF that encapsulates reorgchk_tb_stats and...
7
by: ngocviet | last post by:
I have a text like this: "Thuyền Và Biển" How to convert it to: "Thuyền Và Biển" Please help!
10
by: steve.lorimer | last post by:
I'm looking for a pre-processor command that will allow me to resolve const strings into const char literals at compile time. Looking at the code below, I can take 5 characters and create a...
3
by: Army1987 | last post by:
Is there anything wrong with this program? It seems to behave strangely if I give stdin EOF when asked for the character set... /* BEGIN pwdgen.c */ #include <stdio.h> #include "random.h"...
4
by: sajidali | last post by:
i want to save the password into database after applying hashing to them. how could this be possible in .Net C# you coorporation will be highly appreciated.
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
3
oranoos3000
by: oranoos3000 | last post by:
hi I have a page for registration in my site in this page after validation form I cashed password of user by function md5 and then this hashed password save in database I want to recycled the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.