Created
July 11, 2025 07:35
-
-
Save trycf/d78294af5bdab83e721cdae6f7f5e663 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains hidden or 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
<cfscript> | |
originalText = "Hello World!"; | |
// Step 1: Convert string to binary | |
binaryData = ToBinary( ToBase64(originalText) ); // this is NOT what you want here | |
// Instead: Convert string to raw bytes (Java-style) | |
byteArray = CharsetDecode(originalText, "utf-8"); | |
// Step 2: Encode binary to Base64 | |
encodedBase64 = ToBase64(byteArray); | |
decodedText = ToString(ToBinary(encodedBase64)); | |
// Output | |
writeOutput("Original Text: " & originalText & "<br>"); | |
writeOutput("Encoded Base64 (safe for ToString(ToBinary())): " & encodedBase64); | |
writeOutput("<br>Decoded Text (ToString(ToBinary())): " & decodedText); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment