Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password encryption - c#

Tags:

javascript

c#

md5

Trying to simulate a file upload using HTTPWebRequest. The client side is using Md5.js from this developer MD5.js

In my C# code I am generating the encyptered string as such

public string PasswordHash(string password, string Key)
{
    ASCIIEncoding encoding = new ASCIIEncoding();
    HMACMD5 hmacmd = new HMACMD5(encoding.GetBytes(Key));
    byte[] bytes = encoding.GetBytes(password);
    byte[] byteBuffer= hmacmd.ComputeHash(bytes);
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < buffer3.Length; i++)
    {
        builder.Append(byteBuffer[i].ToString("x2"));
    }
    return builder.ToString().ToLower();
}

The function from MD5.js being used is next:

function hex_hmac_md5(k, d) {
    return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
}

Using fiddler I captured the key when logging using IE as well as the encrypted password. The password generated by my code using C# and same key does not match that of what the JavaScript method produces. what can I be missing?

C# pwd:5d2b9c906608d8381cef4c24ff045be7 pwd as generated by web site using .js and captured using FIDDLER: f79a31f85da55aa0e3aca07e06568709

like image 237
CapsLock Avatar asked Mar 12 '26 14:03

CapsLock


1 Answers

Are you sure MD5.js is also using ASCII encoding? It looks like it is using UTF8

like image 107
Emond Avatar answered Mar 14 '26 04:03

Emond