MD5转换问题 [英] MD5 conversion problem

查看:95
本文介绍了MD5转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在努力将字符串转换为MD5,我之前从未使用过



我有一个我需要编码的字符串,看起来大概是这样的:


" pva:0.05:101214:pa7735tH:inv_desc = 205308:shp_Emai l = petera_gudzon.net:lang

= ru:shp_PaymentNo = 20040825205308:shp_UserID = pva:sh p_Price = 2.95:shp_HostPlan =

BU:shp_Term = 2"


我是这样做的:


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


它不起作用。当我看到我传递此字符串的页面上的输出时,

它看起来像这样:


''< input type = hidden name = crc value =" System.Byte []">''+


我不知道它应该是什么样子,但可能不喜欢

" System.Byte []"


我做错了什么,但我不知道是什么。


我非常感谢你的帮助。


谢谢你,

Peter Afonin

解决方案

为什么不尝试Convert.ToBase64String呢?通常,您将
二进制数据编码为具有Base64或十六进制字符串编码的字符串。


另外,请注意使用ASCII编码转换输入字符串

二进制。如果它包含任何非ASCII字符,你将丢弃数据

。 UTF8更安全。无论你做什么,如果你打算用它进行比较,请确保你总是以同样的方式计算哈希值。


HTH,


Joe K.


" Peter Afonin" < pv*@speakeasy.net>在消息中写道

news:eJ ************** @ TK2MSFTNGP11.phx.gbl ...

你好,
我正在努力将字符串转换为MD5,我之前从未使用过它。

我有一个我需要编码的字符串,看起来很像这:

" pva:0.05:101214:pa7735tH:inv_desc = 205308:shp_Emai l = petera_gudzon.net:lang

= ru:shp_PaymentNo = 20040825205308:shp_UserID = pva :sh p_Price = 2.95:shp_HostPlan = BU:shp_Term = 2"

我这样做:

Dim hashedBytes As Byte()
昏暗md5作为新的MD5CryptoServiceProvider
Dim编码器作为新的ASCIIEncoding
hashedBytes = md5.ComputeHash(encoder.GetBytes(sCRC))
Dim sNewCRC as String = Convert.ToString(md5.ComputeHash(hashedBytes))

它不起作用。当我在页面上看到我传递
字符串的输出时,它看起来像这样:

''< input type = hidden name = crc value =" System.Byte [ ]">''+

我不知道它应该是什么样子,但可能不像
System.Byte []"

我做错了什么,但我不知道是什么。

我非常感谢你的帮助。

谢谢你,
Peter Afonin



谢谢你,乔。


我''我试图改变它:


Dim hashedBytes As Byte()

Dim md5 As New MD5CryptoServiceProvider

Dim encoder As新的UTF8Encoding

hashedBytes = md5.ComputeHash(encoder.GetBytes(sCRC))

sCRC = Convert.ToBase64String(md5.ComputeHash(hashedBytes))

Me.crc.Value = sCRC


是的,输出字符串已更改:


''< input type = hidden na me = crc value =" 35r0XmeFIOXs5evTQM0q + w =​​=">''+


但我仍然得到一个糟糕的crc错误。


Peter


" Joe Kaplan(MVP - ADSI)" <乔************* @ removethis.accenture.com>在消息新闻中写了

:uo **************** @ TK2MSFTNGP09.phx.gbl ...

为什么要'你试试Convert.ToBase64String吗?通常,您将二进制数据编码为具有Base64或十六进制字符串编码的字符串。

另外,请注意使用ASCII编码将输入字符串转换为二进制文件。如果它包含任何非ASCII字符,您将丢弃数据。 UTF8更安全。无论你做什么,如果你打算用它进行比较,请确保你以同样的方式计算
哈希。

HTH,

Joe K 。

彼得Afonin < pv*@speakeasy.net>在消息中写道
新闻:eJ ************** @ TK2MSFTNGP11.phx.gbl ...

你好,
我正在努力将字符串转换为MD5,我之前从未使用过。

我有一个字符串,我需要编码,看起来大约是
这个:

" pva:0.05:101214:pa7735tH:inv_desc = 205308:shp_Emai l = petera_gudzon.net:lang



= ru :shp_PaymentNo = 20040825205308:shp_UserID = pva:sh p_Price = 2.95:shp_HostPlan =

BU:shp_Term = 2"

我是这样做:

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

它不起作用。当我在页面上看到我传递此


字符串的输出时,

它看起来像这样:

''< input type =隐藏名称= crc值=" System.Byte []">''+

我不知道它应该是什么样子,但可能不喜欢
" ; System.Byte []"

我做错了什么,但我不知道是什么。

我非常感谢你的帮助。 />
谢谢你,

Peter Afonin




什么给你一个错误的CRC错误?它是下面的代码吗?那看起来好像它应该只返回一个base64编码的MD5哈希,无论是提供什么字符串




它不是''请告诉我你要做什么或输入什么是

功能。


Joe K.


" Peter Afonin" < pv*@speakeasy.net>在消息中写道

news:eQ **************** @ TK2MSFTNGP12.phx.gbl ...

谢谢, Joe。

我试图改变它:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServiceProvider
Dim encoder作为新的UTF8Encoding
hashedBytes = md5.ComputeHash(encoder.GetBytes(sCRC))
sCRC = Convert.ToBase64String(md5.ComputeHash(hashedBytes))
Me.crc.Value = sCRC

是的,输出字符串已更改:

''< input type = hidden name = crc value =" 35r0XmeFIOXs5evTQM0q + w =​​=">''+

但我仍然得到一个坏crc错误。

彼得

Joe Kaplan(MVP - ADSI) <乔************* @ removethis.accenture.com>在消息新闻中写道
:uo **************** @ TK2MSFTNGP09.phx.gbl ...

为什么不试试转换.ToBase64String而不是?通常,您将二进制数据编码为具有Base64或十六进制字符串编码的字符串。

另外,请注意使用ASCII编码将输入字符串
转换为

二进制。如果它包含任何非ASCII字符,那么你将抛出
数据。 UTF8更安全。无论你做什么,请确保你一直计算


hash

,如果你打算用它进行比较的话。

HTH,

Joe K.

Peter Afonin < pv*@speakeasy.net>在消息中写道
新闻:eJ ************** @ TK2MSFTNGP11.phx.gbl ...

你好,
我正在努力将字符串转换为我之前从未使用过的MD5。

我有一个我需要编码的字符串,看起来大概就像


这:
" pva:0.05:101214:pa7735tH:inv_desc = 205308:shp_Emai l = petera_gudzon.net:lang



= ru:shp_PaymentNo = 20040825205308:shp_UserID = pva:sh p_Price = 2.95:shp_HostPlan =

BU: shp_Term = 2"

我这样做:

Dim hashedBytes As Byte()
Dim md5 As New MD5CryptoServiceProvider
Dim encoder作为新的ASCIIEncoding
hashedBytes = md5.ComputeHash(encoder.GetBytes(sCRC))
Dim sNewCRC as String = Convert.ToString(md5.ComputeHash(hashedBytes))

它没有不行。当我在页面上看到我传递此


字符串的输出时,

它看起来像这样:

''< input type =隐藏名称= crc值=" System.Byte []">''+

我不知道它应该是什么样子,但可能不喜欢
" ; System.Byte []"

我做错了什么,但我不知道是什么。

我非常感谢你的帮助。 />
谢谢你,

Peter Afonin





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_Emai l=petera_gudzon.net:lang
=ru:shp_PaymentNo=20040825205308:shp_UserID=pva:sh p_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

解决方案

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" <pv*@speakeasy.net> wrote in message
news:eJ**************@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_Emai l=petera_gudzon.net:lang
=ru:shp_PaymentNo=20040825205308:shp_UserID=pva:sh p_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



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)" <jo*************@removethis.accenture.com> wrote
in message news:uo****************@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" <pv*@speakeasy.net> wrote in message
news:eJ**************@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_Emai l=petera_gudzon.net:lang


=ru:shp_PaymentNo=20040825205308:shp_UserID=pva:sh p_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




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****************@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)" <jo*************@removethis.accenture.com> wrote
in message news:uo****************@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" <pv*@speakeasy.net> wrote in message
news:eJ**************@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_Emai l=petera_gudzon.net:lang


=ru:shp_PaymentNo=20040825205308:shp_UserID=pva:sh p_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





这篇关于MD5转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆