Skip to content

Instantly share code, notes, and snippets.

View muraray's full-sized avatar
🎯
Be Water My Friend, Be Water

Murali Ramakrishnan muraray

🎯
Be Water My Friend, Be Water
View GitHub Profile
@muraray
muraray / SQL Base64 Encoding
Created August 4, 2022 09:59
Base64 encoding schemes are commonly used when there is a need to encode binary data, especially when that data needs to be stored and transferred over media that are designed to deal with text. This encoding helps to ensure that the data remains intact without modification during transport. Base64 is used commonly in a number of applications in…
-- BTOA Encode the text string
SELECT CAST(N'' AS XML).value(
'xs:base64Binary(xs:hexBinary(sql:column("bin")))',
'VARCHAR(MAX)'
) Base64Encoding
FROM (
SELECT CAST('StoredValue=' + CAST(1213 as VARCHAR(30)) + '' AS VARBINARY(MAX)) AS BIN)
AS EncryptedStudentId;
-- ATOB Decode the Base64-encoded string