Question Need help with MD5 hashing with salt

D4RKKNIGH7

Member
Joined
Sep 13, 2011
Messages
12
Programming Experience
5-10
Hey guys,

I have a small problem I have been working on for the last few hours.

What I am trying to do is make a program that you are able to log into. But to be able to log into it you need to have an account on my forum. I am using MyBB and I have the SALT and Encrypted strings, but when ever i try to hash my own string it doesn't match up.

String im trying to hash: lolcake
the hashed string:
a4ec54ee776c96ca5441aca7e052fc35
salt:
AiAZW8VT

String i get when i use the code below:
HQ6roMkvv2BpXsS+FZSb9A==
Code im using
VB.NET:
Dim strText As String = "lolcake"        
Dim salt As String = "AiAZW8VT"


        Dim bytHashedData As Byte()
        Dim encoder As New UTF8Encoding()
        Dim md5Hasher As New MD5CryptoServiceProvider


        ' Get Bytes for "password" 
        Dim passwordBytes As Byte() = encoder.GetBytes(strText)


        ' Get Bytes for "salt" 
        Dim saltBytes As Byte() = encoder.GetBytes(salt)


        ' Creat new Array to store both "password" and "salt" bytes 
        Dim passwordAndSaltBytes As Byte() = _
        New Byte(passwordBytes.Length + saltBytes.Length - 1) {}


        ' Store "password" bytes 
        For i As Integer = 0 To passwordBytes.Length - 1
            passwordAndSaltBytes(i) = passwordBytes(i)
        Next


        ' Append "salt" bytes 
        For i As Integer = 0 To saltBytes.Length - 1
            passwordAndSaltBytes(i + passwordBytes.Length) = saltBytes(i)
        Next


        ' Compute hash value for "password" and "salt" bytes 
        bytHashedData = md5Hasher.ComputeHash(passwordAndSaltBytes)


        ' Convert result into a base64-encoded string. 
        Dim hashValue As String
        hashValue = Convert.ToBase64String(bytHashedData)


        MsgBox(hashValue.ToString)


 
According to research MyBB uses this function to hash:
md5(md5($salt).md5($password))
md5 in that function returns a string where each hashed byte is represented as two-digit lower-case hex.
You can for example define two helper lambda functions like this:
Dim md5Hasher As New Security.Cryptography.MD5CryptoServiceProvider
Dim bytes2hex = Function(bytes() As Byte) String.Join("", Array.ConvertAll(bytes, Function(b) b.ToString("x2")))
Dim md5 = Function(s As String) bytes2hex(md5Hasher.ComputeHash(System.Text.Encoding.UTF8.GetBytes(s)))

then you'll get pretty much the same functions calls:
 Dim pass As String = "lolcake"
Dim salt As String = "AiAZW8VT"

Dim hash = md5(md5(salt) & md5(pass))
'result: a4ec54ee776c96ca5441aca7e052fc35
 
Back
Top