Re: MD5 conversion problem

From: Peter Afonin (peter_at_gudzon.net)
Date: 08/27/04


Date: Fri, 27 Aug 2004 15:47:10 -0700

Thank you, Joe!

Peter

"Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
in message news:eB8IzPFjEHA.2696@TK2MSFTNGP11.phx.gbl...
> Ah, this is the hex encoding thing I mentioned in my first post and didn't
> provide an example for. You can either use the BitConverter class to
> convert the byte[] to hex digits and then strip out the - characters it
puts
> in between or using something like my function called ConvertToOctetString
> that you can do a Google groups search for that does this. It basically
> just uses a StringBuilder and the X2 format code to loop over the bytes
and
> build the string.
>
> Also, MAKE SURE that the vendor is calculating the MD5 of the data using
the
> same encoding that you are (UTF8, ACSII, UTF16, etc.) or else your input
> byte array may be different and thus your hash will be different.
>
> HTH,
>
> Joe K.
>
> "Peter Afonin" <pva@speakeasy.net> wrote in message
> news:utMGDDAjEHA.2544@TK2MSFTNGP10.phx.gbl...
> > Joe, I'm connecting an online store to the payment system. I need to
pass
> > this string to this payment gateway, and it will return me another
string
> > back, confirming that the payment was successful.
> >
> > I contacted the techsupport of this gateway. They said that I don't have
> to
> > convert my string to Base64. I need to convert every byte to 16-bit
number
> > or something like this. They don't use ASP.Net, so couldn't give me an
> exact
> > code. They said that it should look approximately like this:
> >
> > StringBuilder sb = new StringBuilder();
> >
> > for (int i=0;i<hash.Length;i++)
> > sb.Append(hash[i].ToString("x").PadLeft(2,'0'));
> >
> > return sb.ToString();
> >
> > How it should look in VB.Net?
> >
> > Thank you,
> >
> > Peter
> >
> >
> > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
wrote
> > in message news:OJQ8p$%23iEHA.3988@tk2msftngp13.phx.gbl...
> > > What is giving you a "bad CRC" error? Is it the code below? That
looks
> > > like it should just return a base64 encoded MD5 hash of whatever
string
> > was
> > > provided.
> > >
> > > It isn't clear to me what you are trying to do or what the input is in
> the
> > > funtion.
> > >
> > > Joe K.
> > >
> > > "Peter Afonin" <pva@speakeasy.net> wrote in message
> > > news:eQeJri%23iEHA.3612@TK2MSFTNGP12.phx.gbl...
> > > > Thank you, Joe.
> > > >
> > > > I've tried to change it like this:
> > > >
> > > > Dim hashedBytes As Byte()
> > > > Dim md5 As New MD5CryptoServiceProvider
> > > > Dim encoder As new UTF8Encoding
> > > > hashedBytes = md5.ComputeHash(encoder.GetBytes(sCRC))
> > > > sCRC = Convert.ToBase64String(md5.ComputeHash(hashedBytes))
> > > > Me.crc.Value = sCRC
> > > >
> > > > Yes, the output string has changed:
> > > >
> > > > '<input type=hidden name=crc value="35r0XmeFIOXs5evTQM0q+w==">'+
> > > >
> > > > But I'm still getting a "bad crc" error.
> > > >
> > > > Peter
> > > >
> > > > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
> > wrote
> > > > in message news:uoBsCL%23iEHA.4024@TK2MSFTNGP09.phx.gbl...
> > > > > Why don't you try Convert.ToBase64String instead? Typically, you
> > encode
> > > > > binary data as a string with either Base64 or hex string encoding.
> > > > >
> > > > > Also, be careful about using ASCII encoding to convert the input
> > string
> > > to
> > > > > binary. If it includes any non-ASCII characters, you'll be
throwing
> > > data
> > > > > away. UTF8 is safer. Whatever you do, make sure you alway
compute
> > the
> > > > hash
> > > > > the same way if you are going to be using it for a comparison.
> > > > >
> > > > > HTH,
> > > > >
> > > > > Joe K.
> > > > >
> > > > > "Peter Afonin" <pva@speakeasy.net> wrote in message
> > > > > news:eJWO769iEHA.3928@TK2MSFTNGP11.phx.gbl...
> > > > > > Hello,
> > > > > >
> > > > > > I'm struggling with the string conversion to MD5 which I've
never
> > user
> > > > > > before.
> > > > > >
> > > > > > I have a string that I need to encode which looks approximately
> like
> > > > this:
> > > > > >
> > > > > >
> > > >
> >
"pva:0.05:101214:pa7735tH:inv_desc=205308:shp_Email=petera_gudzon.net:lang
> > > > > >
> > > > >
> > > >
> > >
> >
>
=ru:shp_PaymentNo=20040825205308:shp_UserID=pva:shp_Price=2.95:shp_HostPlan=
> > > > > > BU:shp_Term=2"
> > > > > >
> > > > > > I'm doing it this way:
> > > > > >
> > > > > > Dim hashedBytes As Byte()
> > > > > > Dim md5 As New MD5CryptoServiceProvider
> > > > > > Dim encoder As New ASCIIEncoding
> > > > > > hashedBytes = md5.ComputeHash(encoder.GetBytes(sCRC))
> > > > > > Dim sNewCRC as String =
> > Convert.ToString(md5.ComputeHash(hashedBytes))
> > > > > >
> > > > > > It doesn't work. When I see the output on the page where I pass
> this
> > > > > string,
> > > > > > it looks like this:
> > > > > >
> > > > > > '<input type=hidden name=crc value="System.Byte[]">'+
> > > > > >
> > > > > > I don't know exactly how it should look like, but probably not
> like
> > > > > > "System.Byte[]"
> > > > > >
> > > > > > I'm doing something wrong, but I don't know what.
> > > > > >
> > > > > > I would really appreciate your help.
> > > > > >
> > > > > > Thank you,
> > > > > >
> > > > > > Peter Afonin
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Re: Single record merging
    ... Public Function LPTSTRtoString(ByVal lngPtr As Long) As String ... At this point it's too late, and there's no way to get the ASK to modify the query. ... Peter Jamieson ... Then you specify the destination and use ...
    (microsoft.public.word.mailmerge.fields)
  • Re: shell - open document
    ... I had to put in 0& as suggested by Peter T. ... ByVal lpClassName As String, ByVal lpWindowName As String) As Long ... Dim Returnvalue as Variant ... Private Const SW_SHOWNORMAL As Long = 1 ...
    (microsoft.public.excel.programming)
  • Re: What is default property of name object
    ... Not Set'ing but assigning a string name to the range's name-object property ... Peter T ... but I understand Clara's confusion. ... the default property of the Name object is RefersTo which as ...
    (microsoft.public.excel.programming)
  • Re: What is default property of name object
    ... Not Set'ing but assigning a string name to the range's name-object ... Peter T ... should not work, as the default property for a Name is RefersTo, ... Set rng = ...
    (microsoft.public.excel.programming)
  • Re: Passing a lot of parameters in constructor?
    ... the object creation might involved over 30 parameters, ... Person peter = new Person; ... So why did I say 'safety' of design? ... Person(String name, int age, int housenumber, String firstLine, String ...
    (comp.object)