Page 1 of 1

storing asp.net md5 byte array in mysql

Posted: Fri 02 Sep 2011 02:45
by Digirolomo
I am attempting to store an md5 hash of a password in a mysql table.

here's the code to generate the hash:

Dim md5Hasher as New MD5CryptoServiceProvider()

Dim hashedBytes as Byte()
Dim encoder as New UTF8Encoding()

hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(somestring.text))

This produces a byte array. What is the best method of storing this byte array in mysql? Do I have to convert this to a string somehow then save? The perferred solution would be to save this in a binary field type. I'm certain this won't work..

Dim paramPwd as mysqlSqlParameter
paramPwd = New mySqlParameter("@Password", SqlDbType.Binary, 16)
paramPwd.Value = hashedBytes

Posted: Thu 08 Sep 2011 13:30
by Shalex

Code: Select all

Dim paramPwd as mysqlSqlParameter
paramPwd = New mySqlParameter("@Password", SqlDbType.Binary, 16)
paramPwd.Value = hashedBytes
This code should work. Be aware that:
1) the name of the MySqlParameter object in the collection of the command should contain the '@' prefix only in the case when parameter in CommandText is used with the '@' prefix: http://www.devart.com/dotconnect/mysql/ ... eters.html;
2) we recommend using MySQL-specific Devart.Data.MySql.MySqlType.Binary instead of System.Data.SqlDbType.Binary.

If this doesn't work, please send us a small test project with the corresponding DDL script to reproduce the issue in our environment.