.NET Equivalent to MD5.hex () in Javascript

I am trying to connect to a website that I made using auth, which uses MD5.hex (password) to encrypt the password before sending it to PHP. How can I get the same encryption in C #?

EDIT1:

Javascript (YUI Library):

pw = MD5.hex(pw); this.chap.value = MD5.hex(pw + this.token.value); 

C # .NET

 string pw = getMD5(getHex(getMD5(getHex(my_password)) + my_token)); 

Utility:

 public string getMD5(string input) { // Create a new instance of the MD5CryptoServiceProvider object. MD5 md5Hasher = MD5.Create(); // Convert the input string to a byte array and compute the hash. byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input)); // Create a new Stringbuilder to collect the bytes // and create a string. StringBuilder sBuilder = new StringBuilder(); // Loop through each byte of the hashed data // and format each one as a hexadecimal string. for (int i = 0; i < data.Length; i++) { sBuilder.Append(data[i].ToString("x2")); } // Return the hexadecimal string. return sBuilder.ToString(); } public string getHex(string asciiString) { string hex = ""; foreach (char c in asciiString) { int tmp = c; hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString())); } return hex; } 
+4
source share
1 answer

Use the .NET MD5 class in the System.Security.Cryptography .

The link above contains an example of a short code; you can also check out the Jeff Attwood CodeProject article . Simplified .NET encryption .

+7
source

Source: https://habr.com/ru/post/1307980/


All Articles