I have this code:

Byte[] OriginalBytes;
Byte[] EncryptedBytes;
MD5 md5;

md5 = new MD5CryptoServiceProvider();
OriginalBytes = UTF8Encoding.Default.GetBytes(OriginalPassword);
EncryptedBytes = md5.ComputeHash(OriginalBytes);

return BitConverter.ToString(EncryptedBytes);

MessageBox.Show("MD5 Hash is: " + EncryptedBytes);

However I get the error

"A return keyword must not be followed by a object expression."

I'm quite new to C# so any help getting this working would be appreciated :)

Recommended Answers

All 2 Replies

Use Convert.ToBase64String() method.

I sorted it in the end using:

Byte[] OriginalBytes;
                    Byte[] EncryptedBytes;

                    MD5 md5;


                    md5 = new MD5CryptoServiceProvider();
                    OriginalBytes = ASCIIEncoding.Default.GetBytes(OriginalPassword);
                    EncryptedBytes = md5.ComputeHash(OriginalBytes);

                    foreach (byte a in EncryptedBytes)
                    {
                        if (a < 16)
                            PasswordHash += "0" + a.ToString("x");
                        else
                            PasswordHash += a.ToString("x");
                    }
                    OriginalPassword = null;

That brings back the MD5 password the same way that PHP does.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.