Solved

convert md5 vb c#

Posted on 2013-06-04
8
272 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
 
LVL 9

Author Comment

by:sevensnake77
ID: 39222286
So I do not need to use MakeByte it is used in one function.?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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 code hide show and toggles. 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…
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…

705 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

14 Experts available now in Live!

Get 1:1 Help Now