Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

convert md5 vb c#

Posted on 2013-06-04
8
Medium Priority
?
281 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
  • 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one 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…

886 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