"Dirk Reske" <_F*******@gmx.net> wrote in message
news:u6**************@TK2MSFTNGP12.phx.gbl...
sorry....you're all right!!
but why does my function
public static byte[] ToByteArray(string str)
{
byte[] arr = new byte[str.Length];
for (int i = 0; i < arr.Length; i++)
arr[i] = (byte)str[i];
return arr;
}
return another array then
System.Text.Encoding.ASCII.GetBytes(str) ??
Because your function truncates the unicode character to lower 8-bits,
whereas the ASCII encoding is defined as 7-bit, and all characters out of
the range 0..127 are converted to '?' (which is the 0x3F you have
encountered at the beginning).
It's generally not a good idea to use strings as a storage for binary data,
unless you really know what you're doing. I suggest you rewrite the
Authorization.GenerateKey() function to return byte[] instead of string.
HTH,
Stefan