System.Text.Encoding.UTF8.GetBytes(s) different values for a string on the same computer, different programs
I'm doing a
System.Text.Encoding.UTF8.GetBytes(s)
on开发者_如何学Python 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"
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.
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.
精彩评论