Skip to content

Instantly share code, notes, and snippets.

@muraray
Created August 4, 2022 09:59
Show Gist options
  • Save muraray/110c44573650837dc8bbc413338c81bd to your computer and use it in GitHub Desktop.
Save muraray/110c44573650837dc8bbc413338c81bd to your computer and use it in GitHub Desktop.
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
SELECT
CAST(
CAST(N'' AS XML).value(
'xs:base64Binary("U3RvcmVkVmFsdWU9MTIxMw==")'
, 'VARBINARY(MAX)'
)
AS VARCHAR(MAX)
) ASCIIEncoding
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment