Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trycf/43d95721e4200e9971e028ad3138c8eb to your computer and use it in GitHub Desktop.
Save trycf/43d95721e4200e9971e028ad3138c8eb 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);
// Output
writeOutput("Original Text: " & originalText & "<br>");
writeOutput("Encoded Base64 (safe for ToString(ToBinary())): " & encodedBase64);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment