954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MD5 Encryption return error

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 :)

painejake
Newbie Poster
6 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

Use Convert.ToBase64String() method.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

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.

painejake
Newbie Poster
6 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: