I have an SQL function for converting a string to a base64-encoded string. The only problem is is that UTF8 is not being used, which I can tell because I have a seperate C# tool that gives a different output.
SQL Function:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[Base64Encode] ( @sInput NVARCHAR(max) )
RETURNS NVARCHAR(max)
BEGIN
DECLARE @vInput VARBINARY(max)
DECLARE @sEncodedOutput NVARCHAR(max)
set @vInput = convert(varbinary(max), @sInput)
set @sEncodedOutput = cast('' as xml).value('xs:base64Binary(sql:variable("@vInput"))', 'NVARCHAR(max)')
RETURN @sEncodedOutput
END
C#
try
{
encodedValueTextbox.Text = Convert.ToBase64String(
Encoding.UTF8.GetBytes(valueTextbox.Text));
}
catch (Exception ex)
{
encodedValueTextbox.Text = ex.Message;
}
Is there a way to get SQL to use UTF8?