Solved

convert md5 vb c#

Posted on 2013-06-04
8
277 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

830 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