I'm having the issue while converting the string to base 64 for encoding using T-SQL. As I use chatgpt to search and some function like
SELECT BASE64_ENCODE (CAST ('hello world' AS varbinary))
SELECT CAST('string' AS varbinary(max))
FOR XML PATH(''), BINARY BASE64
After that I test with a function using C# as:
Encoding.UTF8.GetString(Convert.FromBase64String(base64Encoded)
However, it returns the undesired result. For example, I have a string ABCD and when using the above methods to convert it into Base64 in SQL with the above methods it returns as QQBCAEMARAA=, in which will return as A�B�C�D� for me later by the decode function while testing with Postman.
So in here I want the string ABCD to be converted into QUJDRAo= according to https://www.base64encode.org/, does anyone know to deal with this issue ?
BASE64_ENCODE
is currently only available in Azure solutions, not on premises.varbinary
orvarchar
without a length, don't ever do this.