Solved

convert md5 vb c#

Posted on 2013-06-04
8
275 Views
Last Modified: 2013-06-05
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

    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

the code I try to use the converters but i get an error still in the code saying. string does not exists in the current contest.
0
Comment
Question by:sevensnake77
  • 4
  • 4
8 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39220407
How about this?
    Function MD5Encrypt(ByVal text As String) As String
        Dim MD5 As New System.Security.Cryptography.MD5CryptoServiceProvider
        Dim bytes() As Byte = System.Text.ASCIIEncoding.ASCII.GetBytes(text)
        Return System.Text.ASCIIEncoding.ASCII.GetString(MD5.ComputeHash(bytes, 0, bytes.Length))
    End Function

Open in new window


Converted to?
        public string MD5Encrypt(string text)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider MD5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(text);
            return System.Text.ASCIIEncoding.ASCII.GetString(MD5.ComputeHash(bytes, 0, bytes.Length));
        }

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 39222159
what about
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
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 500 total points
ID: 39222169
That was taken care of in the line #3:

    Dim bytes() As Byte = System.Text.ASCIIEncoding.ASCII.GetBytes(text)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 9

Author Comment

by:sevensnake77
ID: 39222286
So I do not need to use MakeByte it is used in one function.?
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 500 total points
ID: 39222314
No.

Note that your original signature was:

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

and I changed that to:

    Function MD5Encrypt(ByVal text As String) As String

So the original received a Byte Array, while the new directly receives a String since we can easily convert the string to a byte array with a one-liner and don't need the helper function anymore.
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 500 total points
ID: 39222323
*No...you don't need MakeByte()....    =)
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 39222349
Thanks
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 39222353
Thanks again
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now