convert function to c#

trying to convert this. I use the vb to c# converter but in my forloop returns a
 for (i = 1; i <= Strings.Len(text); i++)
which is an error using Strings

Function MD5Encrypt(ByVal text() As Byte) As String

        Dim j As Integer = 0
        Dim retString As String
        Dim MD5 As New System.Security.Cryptography.MD5CryptoServiceProvider
        Dim tout() As Byte = MD5.ComputeHash(text, 0, text.Length)
        MD5 = Nothing

        For j = 0 To tout.Length - 1
            retString += Chr(tout(j))
        Next
        Return retString

    End Function

Open in new window

LVL 9
Seven priceFull StackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
string MD5Encrypt(byte[] text)
{
    int j = 0;
    string retString;
    System.Security.Cryptography.MD5CryptoServiceProvider MD5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
    byte[] tout = MD5.ComputeHash(text, 0, text.Length);
    MD5 = null;

    for (j = 0; j < tout.Length; j++)
    {
        retString += Convert.ToChar(tout[j]);
    }

    return retString;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seven priceFull StackAuthor Commented:
_Username=   obj.MakeByte(_Username.Trim);

The best overloaded method match for 'EncryptText.MakeByte(byte[])' has some invalid arguments      

Ok when I am calling it i get an error.
Argument 1: cannot convert from 'method group' to 'byte[]'
0
käµfm³d 👽Commented:
VB is a bit more forgiving on parentheses usage (something I don't appreciate for the very thing you are encountering here). Add parens to your Trim call in C#.

e.g.

_Username=   obj.MakeByte(_Username.Trim());

Open in new window

0
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Seven priceFull StackAuthor Commented:
I done that but I still get this error not sure what it means.

The best overloaded method match for MakeByte(byte[])' has some invalid arguments
0
Seven priceFull StackAuthor Commented:
ok when I add a null no error. do you think this is because the value username is a string?

MakeByte(null)
0
Seven priceFull StackAuthor Commented:
I am sorry gave you the wrong one.

 
Function MakeByte(ByVal text As String) As Byte()

        Dim i As Integer
        Dim ba(text.Length - 1) As Byte
        For i = 1 To Len(text)
            ba(i - 1) = Asc(Mid(text, i, 1))
        Next

        Return ba

    End Function

Open in new window

0
Seven priceFull StackAuthor Commented:
thanks on the other error i will repost. But thanks again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.