Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am trying to establish a connection to a Server using MD5 Authentication.
The server returns me the challenge key,,,,
How can I use it to encrypt my password and send it back to the server....
The encryption method currently I know needs Password Hash, Salt Key, and VI Code...
How Can I make it ,,,, Please Help friends...

C#
static readonly string PasswordHash = "PasswordHash";
        static readonly string SaltKey = "SaltKey";
        static readonly string VIKey = "@1B2c3D4e5F6g7H8";

        public static string Encrypt(string plainText)
        {
            byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

            byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
            var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
            var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));

            byte[] cipherTextBytes;

            using (var memoryStream = new MemoryStream())
            {
                using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                {
                    cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                    cryptoStream.FlushFinalBlock();
                    cipherTextBytes = memoryStream.ToArray();
                    cryptoStream.Close();
                }
                memoryStream.Close();
            }
            return Convert.ToBase64String(cipherTextBytes);
        }
Posted

1 solution

MD5 is not an encryption algorithm - it is a hashing algorithm. The big difference is that encryption can be reversed, hashing can't. So once you have hashed your password (combined with the challenge key in some way) your password cannot be derived from the information you share with the server. Using MD5 is pretty simple - google "MD5 C# MSDN" and you should find out how to do it, but as for the actual mechanics of how to use it in your specific case we cannot help.

You need to talk to the people running the server (or who coded the software running on the server) to find out exactly how you combine your password with the challenge key because there is no "one right way" to do it, and any slight different in the mechanism will produce a MD5 value that fails to work.

Sorry, but we can't help you - only the server people can.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900