Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

convert md5 vb c#

Posted on 2013-06-04
8
Medium Priority
?
280 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:Seven price
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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:Seven price
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 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 2000 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 top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 9

Author Comment

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

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 2000 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 86

Assisted Solution

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

Author Comment

by:Seven price
ID: 39222349
Thanks
0
 
LVL 9

Author Closing Comment

by:Seven price
ID: 39222353
Thanks again
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

715 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