I have base64 string encoding/decoding functions in C# and TSQL, my problem is encoded result from C# differs from encoding result in TSQL.
My goal is:
- C# encoded string should be decoded in TSQL and vice-versa
- Both functions should have an ability to encode/decode unicode characters
C#
Convert.ToBase64String(Encoding.UTF8.GetBytes("test"));
Result: dGVzdA==
TSQL
SELECT CAST(N'' AS XML).value('xs:base64Binary(xs:hexBinary(sql:column("bin")))', 'NVARCHAR(MAX)') Base64Encoding
FROM
(
SELECT CAST(N'test' AS VARBINARY(MAX)) AS bin
) AS bin_sql_server_temp
Result: dABlAHMAdAA=
Any idea how to match the results?