While tracing a bug I have found the following discrepancy between HttpServerUtility.UrlTokenEncode
and Convert.ToBase64String
in conversion to Base64 and back:
string test = "IN ('en-US')";
Console.WriteLine(HttpServerUtility.UrlTokenEncode(Encoding.UTF8.GetBytes(test)));
Console.WriteLine(Convert.ToBase64String(Encoding.UTF8.GetBytes(test)));
The result are slightly different: the first method has an additional trailing zero:
SU4gKCdlbi1VUycp0
SU4gKCdlbi1VUycp
JavaScript btoa()
also gives me the value without trailing zero.
I understand that this zero is just for padding here, but is the second conversion still base64-compliant? Or should we refrain from using HttpServerUtility.UrlTokenEncode
in favor of Convert.ToBase64String
everywhere?