Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trycf/d78294af5bdab83e721cdae6f7f5e663 to your computer and use it in GitHub Desktop.
Save trycf/d78294af5bdab83e721cdae6f7f5e663 to your computer and use it in GitHub Desktop.
TryCF Gist
<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