Created
August 4, 2022 09:59
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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