Re: MD5 conversion problem

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

  • Next message: José Joye: "Re: MD5 conversion problem"
    Date: Thu, 26 Aug 2004 23:40:37 -0700
    
    

    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
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >


  • Next message: José Joye: "Re: MD5 conversion problem"

    Relevant Pages

    • Re: searching what groups a user belong from AD but errorThe Kerberos subsystem encountered an error
      ... I was just about to write back Joe. ... private string BuildFilterOctetString ... Co-author of "The .NET Developer's Guide to Directory Services ... DirectoryEntry searchRoot = new DirectoryEntry( ...
      (microsoft.public.dotnet.framework.aspnet.security)
    • Re: LogonUser access denied
      ... Joe - really appreciate your efforts on this one, i will try the privilege ... private static extern int LogonUser(String lpszUsername, ...
      (microsoft.public.dotnet.framework.aspnet.security)
    • Re: 32-bit programs on Windows x64
      ... tiny individual sequences. ... to compare its input string against every possible ... compare one string against one string, ...
      (microsoft.public.vc.mfc)
    • Re: 32-bit programs on Windows x64
      ... machine has "parallelism" ... to compare its input string against every possible valid ...
      (microsoft.public.vc.mfc)
    • Re: passing a string to a dll
      ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
      (microsoft.public.vc.mfc)