How to generate an MD5 data from the string

P

Peter Afonin

Hello,

I've never been dealing with the security before. Could you please help me
to write a code to generate an MD5 data from a string? I've been using this
example from MSDN:

Function MD5hash(data() As Byte) As Byte()
' This is one implementation of the abstract class MD5.
Dim md5 As New MD5CryptoServiceProvider()

Dim result As Byte() = md5.ComputeHash(data)

Return result
End Function

but perhaps made a mistake converting string to byte and couldn't fix it.

My string looks like this:

sCRC = "avp:" & dblSum.ToString & ":" & CLng(Format(Now, "yyyyMMddHHmmss"))
_
& ":pa0107THOP:shp_UserID=" & sUser _
& ":shp_Price=" & dblPrice.ToString & ":shp_PaymentNo=" _
& CLng(Format(Now, "yyyyMMddHHmmss")) & ":shp_Term=" _
& sTerm & ":shp_Email=" & sEmail

I will be passing this parameter as a querystring.

I would really appreciate your help.

Thank you,
 
P

PL

The absolute simplest way is to use:

string md5= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile( str,"MD5");

where str is your string you want to computer the hash from and the last argument can
be "MD5" or "SHA1"

For more info look this up in the docs.

PL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top