System.Text.Encoding.UTF8.GetBytes(s) 同一台计算机、不同程序上的字符串的不同值
我正在
System.Text.Encoding.UTF8.GetBytes(s)
使用 .NET 2.0 框架在两个不同的程序(一个控制台,一个 Web)中对字符串进行操作,并且返回的编码与这两个程序不同。对于字符串“everything”,我得到相同的结果,但对于字符串“OnI3UwUc”,我得到两个不同的结果。
对于“OnI3UwUc”,6f6e693375777563 对于另一个程序中的“OnI3UwUc”,我得到 4f63493355775563。
在 中,
我尝试将其编写为与我拥有的一些经典 ASP 代码相同的操作:
Dim crypt : Set crypt = CreateObject("Chilkat.Crypt2")
crypt.UnlockComponent("TXTECHCrypt_6X6EnMdFNRCe")
crypt.HashAlgorithm = "sha1"
crypt.CryptAlgorithm = "aes"
crypt.CipherMode = "ecb"
crypt.EncodingMode = "hex"
crypt.SetEncodedKey "100202330405560608790A8B0C9D0EAF","hex"
I'm doing a
System.Text.Encoding.UTF8.GetBytes(s)
on a string in two different programs (one console, one web) using .NET 2.0 framework and the encoding is coming back different from the two. For the string "everything" I get the same result, but for the string "OnI3UwUc" I get two different results.
For The "OnI3UwUc", 6f6e693375777563
For the "OnI3UwUc" in another program, I get 4f63493355775563.
In the
I tried to write this to operate the same as some Classic ASP code I have:
Dim crypt : Set crypt = CreateObject("Chilkat.Crypt2")
crypt.UnlockComponent("TXTECHCrypt_6X6EnMdFNRCe")
crypt.HashAlgorithm = "sha1"
crypt.CryptAlgorithm = "aes"
crypt.CipherMode = "ecb"
crypt.EncodingMode = "hex"
crypt.SetEncodedKey "100202330405560608790A8B0C9D0EAF","hex"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您提到您从其中一个程序获得的 UTF-8 是
6f6e693375777563
。这会解码回“oni3uwuc”
。换句话说,您的其他程序在对它们进行 UTF-8 编码之前将所有字母小写。You mentioned that the UTF-8 you get from one of the programs is
6f6e693375777563
. This decodes back to"oni3uwuc"
. In other words, your other program is lowercasing all the letters before UTF-8-encoding them.这是极不可能的。对两个字符串使用
File.WriteAllText("C:/file1.txt", s)
并仔细比较它们。它们将会有所不同。在极不可能的情况下,它们实际上是相等的,请尝试从这两个程序中删除不影响此输出的所有内容,然后将其发布到 connect.microsoft.com 上,并在此处链接。但请注意,超过 100 行的程序几乎肯定可以进一步缩减。
That is exceedingly unlikely. Use
File.WriteAllText("C:/file1.txt", s)
for both strings, and compare them carefully. They will be different.In the highly unlikely case that they are actually equal, please try removing everything from those two programs that doesn't affect this output, and then post it on connect.microsoft.com, and link here. Note however that programs longer than 100 lines are almost certainly reducible further.