473,573 Members | 2,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MD5 conversion problem

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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang
=ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan =
BU:shp_Term=2"

I'm doing it this way:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As New ASCIIEncoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
Dim sNewCRC as String = Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+

I don't know exactly how it should look like, but probably not like
"System.Byt e[]"

I'm doing something wrong, but I don't know what.

I would really appreciate your help.

Thank you,

Peter Afonin
Nov 18 '05 #1
15 2409
Why don't you try Convert.ToBase6 4String 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" <pv*@speakeasy. net> wrote in message
news:eJ******** ******@TK2MSFTN GP11.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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang
=ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan = BU:shp_Term=2"

I'm doing it this way:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As New ASCIIEncoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
Dim sNewCRC as String = Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+

I don't know exactly how it should look like, but probably not like
"System.Byt e[]"

I'm doing something wrong, but I don't know what.

I would really appreciate your help.

Thank you,

Peter Afonin

Nov 18 '05 #2
Thank you, Joe.

I've tried to change it like this:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As new UTF8Encoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
sCRC = Convert.ToBase6 4String(md5.Com puteHash(hashed Bytes))
Me.crc.Value = sCRC

Yes, the output string has changed:

'<input type=hidden name=crc value="35r0XmeF IOXs5evTQM0q+w= =">'+

But I'm still getting a "bad crc" error.

Peter

"Joe Kaplan (MVP - ADSI)" <jo************ *@removethis.ac centure.com> wrote
in message news:uo******** ********@TK2MSF TNGP09.phx.gbl. ..
Why don't you try Convert.ToBase6 4String 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" <pv*@speakeasy. net> wrote in message
news:eJ******** ******@TK2MSFTN GP11.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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang

=ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan =
BU:shp_Term=2"

I'm doing it this way:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As New ASCIIEncoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
Dim sNewCRC as String = Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+

I don't know exactly how it should look like, but probably not like
"System.Byt e[]"

I'm doing something wrong, but I don't know what.

I would really appreciate your help.

Thank you,

Peter Afonin


Nov 18 '05 #3
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" <pv*@speakeasy. net> wrote in message
news:eQ******** ********@TK2MSF TNGP12.phx.gbl. ..
Thank you, Joe.

I've tried to change it like this:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As new UTF8Encoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
sCRC = Convert.ToBase6 4String(md5.Com puteHash(hashed Bytes))
Me.crc.Value = sCRC

Yes, the output string has changed:

'<input type=hidden name=crc value="35r0XmeF IOXs5evTQM0q+w= =">'+

But I'm still getting a "bad crc" error.

Peter

"Joe Kaplan (MVP - ADSI)" <jo************ *@removethis.ac centure.com> wrote
in message news:uo******** ********@TK2MSF TNGP09.phx.gbl. ..
Why don't you try Convert.ToBase6 4String 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" <pv*@speakeasy. net> wrote in message
news:eJ******** ******@TK2MSFTN GP11.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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang

=ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan =
BU:shp_Term=2"

I'm doing it this way:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As New ASCIIEncoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
Dim sNewCRC as String = Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+

I don't know exactly how it should look like, but probably not like
"System.Byt e[]"

I'm doing something wrong, but I don't know what.

I would really appreciate your help.

Thank you,

Peter Afonin



Nov 18 '05 #4
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.Leng th;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)" <jo************ *@removethis.ac centure.com> wrote
in message news:OJ******** ********@tk2msf tngp13.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" <pv*@speakeasy. net> wrote in message
news:eQ******** ********@TK2MSF TNGP12.phx.gbl. ..
Thank you, Joe.

I've tried to change it like this:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As new UTF8Encoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
sCRC = Convert.ToBase6 4String(md5.Com puteHash(hashed Bytes))
Me.crc.Value = sCRC

Yes, the output string has changed:

'<input type=hidden name=crc value="35r0XmeF IOXs5evTQM0q+w= =">'+

But I'm still getting a "bad crc" error.

Peter

"Joe Kaplan (MVP - ADSI)" <jo************ *@removethis.ac centure.com> wrote
in message news:uo******** ********@TK2MSF TNGP09.phx.gbl. ..
Why don't you try Convert.ToBase6 4String 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" <pv*@speakeasy. net> wrote in message
news:eJ******** ******@TK2MSFTN GP11.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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang
>

=ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan =
> BU:shp_Term=2"
>
> I'm doing it this way:
>
> Dim hashedBytes As Byte()
> Dim md5 As New MD5CryptoServic eProvider
> Dim encoder As New ASCIIEncoding
> hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
> Dim sNewCRC as String = Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+
>
> I don't know exactly how it should look like, but probably not like
> "System.Byt e[]"
>
> I'm doing something wrong, but I don't know what.
>
> I would really appreciate your help.
>
> Thank you,
>
> Peter Afonin
>
>



Nov 18 '05 #5
By the way, If you want to compute an MD5 ash on a pswd like string and get
the result in a string (eg for storing ashing in a dB), you could use this
wrapper method:
FormsAuthentica tion.HashPasswo rdForStoringInC onfigFile()

José
"Peter Afonin" <pv*@speakeasy. net> wrote in message
news:eJ******** ******@TK2MSFTN GP11.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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang
=ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan =
BU:shp_Term=2"

I'm doing it this way:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As New ASCIIEncoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
Dim sNewCRC as String = Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+

I don't know exactly how it should look like, but probably not like
"System.Byt e[]"

I'm doing something wrong, but I don't know what.

I would really appreciate your help.

Thank you,

Peter Afonin

Nov 18 '05 #6
Thank you, I'll try.

Peter

"José Joye" <jo*******@KILL THESPAMSbluewin .ch> wrote in message
news:uI******** *****@TK2MSFTNG P12.phx.gbl...
By the way, If you want to compute an MD5 ash on a pswd like string and get the result in a string (eg for storing ashing in a dB), you could use this
wrapper method:
FormsAuthentica tion.HashPasswo rdForStoringInC onfigFile()

José
"Peter Afonin" <pv*@speakeasy. net> wrote in message
news:eJ******** ******@TK2MSFTN GP11.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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang =ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan = BU:shp_Term=2"

I'm doing it this way:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As New ASCIIEncoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
Dim sNewCRC as String = Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+

I don't know exactly how it should look like, but probably not like
"System.Byt e[]"

I'm doing something wrong, but I don't know what.

I would really appreciate your help.

Thank you,

Peter Afonin


Nov 18 '05 #7
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 ConvertToOctetS tring
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" <pv*@speakeasy. net> wrote in message
news:ut******** ******@TK2MSFTN GP10.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.Leng th;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)" <jo************ *@removethis.ac centure.com> wrote
in message news:OJ******** ********@tk2msf tngp13.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" <pv*@speakeasy. net> wrote in message
news:eQ******** ********@TK2MSF TNGP12.phx.gbl. ..
Thank you, Joe.

I've tried to change it like this:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServic eProvider
Dim encoder As new UTF8Encoding
hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
sCRC = Convert.ToBase6 4String(md5.Com puteHash(hashed Bytes))
Me.crc.Value = sCRC

Yes, the output string has changed:

'<input type=hidden name=crc value="35r0XmeF IOXs5evTQM0q+w= =">'+

But I'm still getting a "bad crc" error.

Peter

"Joe Kaplan (MVP - ADSI)" <jo************ *@removethis.ac centure.com>

wrote in message news:uo******** ********@TK2MSF TNGP09.phx.gbl. ..
> Why don't you try Convert.ToBase6 4String 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" <pv*@speakeasy. net> wrote in message
> news:eJ******** ******@TK2MSFTN GP11.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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang > >
>

=ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan =
> > BU:shp_Term=2"
> >
> > I'm doing it this way:
> >
> > Dim hashedBytes As Byte()
> > Dim md5 As New MD5CryptoServic eProvider
> > Dim encoder As New ASCIIEncoding
> > hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
> > Dim sNewCRC as String = Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+
> >
> > I don't know exactly how it should look like, but probably not like > > "System.Byt e[]"
> >
> > I'm doing something wrong, but I don't know what.
> >
> > I would really appreciate your help.
> >
> > Thank you,
> >
> > Peter Afonin
> >
> >
>
>



Nov 18 '05 #8
Thank you, Joe!

Peter

"Joe Kaplan (MVP - ADSI)" <jo************ *@removethis.ac centure.com> wrote
in message news:eB******** ******@TK2MSFTN GP11.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 ConvertToOctetS tring
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" <pv*@speakeasy. net> wrote in message
news:ut******** ******@TK2MSFTN GP10.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.Leng th;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)" <jo************ *@removethis.ac centure.com> wrote in message news:OJ******** ********@tk2msf tngp13.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" <pv*@speakeasy. net> wrote in message
news:eQ******** ********@TK2MSF TNGP12.phx.gbl. ..
> Thank you, Joe.
>
> I've tried to change it like this:
>
> Dim hashedBytes As Byte()
> Dim md5 As New MD5CryptoServic eProvider
> Dim encoder As new UTF8Encoding
> hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
> sCRC = Convert.ToBase6 4String(md5.Com puteHash(hashed Bytes))
> Me.crc.Value = sCRC
>
> Yes, the output string has changed:
>
> '<input type=hidden name=crc value="35r0XmeF IOXs5evTQM0q+w= =">'+
>
> But I'm still getting a "bad crc" error.
>
> Peter
>
> "Joe Kaplan (MVP - ADSI)" <jo************ *@removethis.ac centure.com>

wrote
> in message news:uo******** ********@TK2MSF TNGP09.phx.gbl. ..
> > Why don't you try Convert.ToBase6 4String 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" <pv*@speakeasy. net> wrote in message
> > news:eJ******** ******@TK2MSFTN GP11.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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang > > >
> >
>

=ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan =
> > > BU:shp_Term=2"
> > >
> > > I'm doing it this way:
> > >
> > > Dim hashedBytes As Byte()
> > > Dim md5 As New MD5CryptoServic eProvider
> > > Dim encoder As New ASCIIEncoding
> > > hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
> > > Dim sNewCRC as String =

Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+
> > >
> > > I don't know exactly how it should look like, but probably not like > > > "System.Byt e[]"
> > >
> > > I'm doing something wrong, but I don't know what.
> > >
> > > I would really appreciate your help.
> > >
> > > Thank you,
> > >
> > > Peter Afonin
> > >
> > >
> >
> >
>
>



Nov 18 '05 #9
Hello Joe,

I found a code that should do exactly the same as in the example in my
previous message, but still doing something wrong, because the payment
gateway gives me a message that the string is bad. There is a chance that
the code itself is OK, but the data I put in is bad. But do you see anything
wrong with this code? I would appreciate your comments very much. Peter.

Dim enc As Encoder = System.Text.Enc oding.Unicode.G etEncoder()

Dim unicodeText() As Byte
unicodeText = System.Text.Uni codeEncoding.Un icode.GetBytes( sCRC)

enc.GetBytes(sC RC.ToCharArray( ), 0, sCRC.Length, unicodeText, _
0, True)

Dim oMD5 As New System.Security .Cryptography.M D5CryptoService Provider
Dim result() As Byte = oMD5.ComputeHas h(unicodeText)

Dim sb As New StringBuilder
Dim i As Integer = 0
For i = 0 To CType(result.Le ngth - 1, Integer)
sb.Append(resul t(i).ToString(" X").PadLeft( 2, "0"))
Next

sCRC = sb.ToString
"Joe Kaplan (MVP - ADSI)" <jo************ *@removethis.ac centure.com> wrote
in message news:eB******** ******@TK2MSFTN GP11.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 ConvertToOctetS tring
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" <pv*@speakeasy. net> wrote in message
news:ut******** ******@TK2MSFTN GP10.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.Leng th;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)" <jo************ *@removethis.ac centure.com> wrote in message news:OJ******** ********@tk2msf tngp13.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" <pv*@speakeasy. net> wrote in message
news:eQ******** ********@TK2MSF TNGP12.phx.gbl. ..
> Thank you, Joe.
>
> I've tried to change it like this:
>
> Dim hashedBytes As Byte()
> Dim md5 As New MD5CryptoServic eProvider
> Dim encoder As new UTF8Encoding
> hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
> sCRC = Convert.ToBase6 4String(md5.Com puteHash(hashed Bytes))
> Me.crc.Value = sCRC
>
> Yes, the output string has changed:
>
> '<input type=hidden name=crc value="35r0XmeF IOXs5evTQM0q+w= =">'+
>
> But I'm still getting a "bad crc" error.
>
> Peter
>
> "Joe Kaplan (MVP - ADSI)" <jo************ *@removethis.ac centure.com>

wrote
> in message news:uo******** ********@TK2MSF TNGP09.phx.gbl. ..
> > Why don't you try Convert.ToBase6 4String 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" <pv*@speakeasy. net> wrote in message
> > news:eJ******** ******@TK2MSFTN GP11.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:10121 4:pa7735tH:inv_ desc=205308:shp _Email=petera_g udzon.net:lang > > >
> >
>

=ru:shp_Payment No=200408252053 08:shp_UserID=p va:shp_Price=2. 95:shp_HostPlan =
> > > BU:shp_Term=2"
> > >
> > > I'm doing it this way:
> > >
> > > Dim hashedBytes As Byte()
> > > Dim md5 As New MD5CryptoServic eProvider
> > > Dim encoder As New ASCIIEncoding
> > > hashedBytes = md5.ComputeHash (encoder.GetByt es(sCRC))
> > > Dim sNewCRC as String =

Convert.ToStrin g(md5.ComputeHa sh(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.B yte[]">'+
> > >
> > > I don't know exactly how it should look like, but probably not like > > > "System.Byt e[]"
> > >
> > > I'm doing something wrong, but I don't know what.
> > >
> > > I would really appreciate your help.
> > >
> > > Thank you,
> > >
> > > Peter Afonin
> > >
> > >
> >
> >
>
>



Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3934
by: Vladimir Khvostov | last post by:
Hi, We have some DB2 table on the host that has varchar(3200) columns that are used to store binary data (I know that "varchar(3200) for bit data" should have been used, by modifying host table is not an option at this time). I wrote a Win32 application, which is using DB2 Connect and ODBC to pull the data from the host. I am passing...
31
6594
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one variable becomes 364 and the other one becomes 365. Does anyone have any insight to what the problem is? Thanks in advance. Bjørn
11
7603
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type Test. I expected the same error from the following line, but it compiles fine. The double is silently truncated to an int and then fed in to the...
3
4443
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while calling the constructor 'MyString::MyString(const wchar_t *)' c:\SrNet\jury\JuryTest.h(21) : see declaration of 'MyString::MyString' The class...
0
1184
by: VB Programmer | last post by:
Simple ASP.NET 1 site. Opened solution in beta 2 of 2.0. Ran thru conversion wizard and it states: "Conversion Complete. There were some errors during conversion." I view the conversion log and for the project there is 1 error... http://localhost/Watersmark/ Conversion Issues - http://localhost/Watersmark/: ERROR: Failed to backup...
4
2901
by: Påhl Melin | last post by:
I have some problems using conversion operators in C++/CLI. In my project I have two ref class:es Signal and SignalMask and I have an conversion function in Signal to convert Signal:s to SignalMask:s. The reason is I have a free function called WaitSignal that accepts av SignalMask where Signals parameters are supposed to implicitly be...
14
2213
by: Richard G. Riley | last post by:
Would it be wrong to use "implicit casting" instead of the standards "implicit conversion" when talking about implicit conversions between certain data types. The standard mentions "explicit conversion" for a cast operation
6
2788
by: Dhirendra Singh | last post by:
Hi, The following C++ program is not compiling on my system. #include <iostream> using namespace std; class complex { double re, im; public: complex( ) :re(0), im(0) {}
4
2170
by: Coleen | last post by:
Hi All :-) I'm new to this site. I've been trying to convert several .Net 2003 web applications and getting tons of conversion errors. I found this site to help walk me through the conversion process: http://webproject.scottgu.com/VisualBasic/Migration2/Migration2.aspx which is great, however, when I follow the steps in this tutorial...
8
5078
by: Nikola | last post by:
Hello, I'm writing a String class for C++ and I'm getting the following error message when using operator: test.cpp: In function ‘int main()’: test.cpp:7: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: string.h:19: note: candidate 1: char...
0
7781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7699
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5594
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5292
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3733
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3733
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1041
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.