DEV Community 👩‍💻👨‍💻

Joe Enos
Joe Enos

Posted on

Base64 Conversions in SQL Server

SQL Server has the ability to base-64 encode or decode, but the way it does it is really kind of funky.

.NET has nice simple Convert.ToBase64String and Convert.FromBase64String methods, but it's a little more work in SQL Server.

Converting from base 64 to bytes:

CAST(@Input AS XML).value('.', 'VARBINARY(MAX)');
Enter fullscreen mode Exit fullscreen mode

Convert from bytes to base 64:

SELECT @Input FOR XML PATH(''), BINARY BASE64
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Head to your account's Settings to...

🌚 Enable dark mode
🔠 Change your default font
📚 Adjust your experience level to see more relevant content