CREATE FUNCTION [dbo].[f_base64_encode](@bin varbinary(max))returns varchar(max)as beginreturn cast(N'' as xml).value('xs:base64Binary(xs:hexBinary(sql:variable("@bin")))', 'varchar(max)')endGOCREATE FUNCTION [dbo].[f_base64_decode](@64 varchar(max))returns varbinary(max)as beginreturn cast(N'' as xml).value('xs:base64Binary(sql:variable("@64"))', 'varbinary(max)')endGO