We recently came across some sample code from a provider for hashing a private key to call a web service, their sample was in VB.NET, which we converted to C #. This led to the hash creating different input data. It turns out that the way to generate the key for encryption was by converting the char array to a string and back to an array of bytes. This led me to the discovery that VB.NET and C # encoders work with some characters by default.
FROM#:
Console.Write(Encoding.Default.GetBytes(new char[] { (char)149 })[0]);
VB:
Dim b As Char() = {Chr(149)} Console.WriteLine(Encoding.Default.GetBytes(b)(0))
C # output is 63, and VB is the correct value for byte 149. if you use any other value, for example 145, etc., the result is consistent.
Passing through debugging, both VB and C # by default encodes SBCSCodePageEncoding.
Does anyone know why this is?
I adjusted the sample code by directly initializing the byte array, which should have been in the first place, but I still want to know why the encoder, which should not be language specific, looks exactly like that.
Annagram
source share