You can use StringToBase64 in OCL expressions when you need to encode text as UTF-8 Base64, for example before placing text in an integration payload or URL parameter.
What StringToBase64 does
StringToBase64 converts a string to its UTF-8 representation and returns that representation encoded as a Base64 string.
For example, encode a clear-text value:
'Hello'.StringToBase64
The result is Base64 text. Base64 is an encoding for transporting data; it is not encryption.
Use Base64 safely in URL parameters
Standard Base64 may contain / and +. These characters may not survive unchanged when you send the value as a URL parameter. If the receiving system uses the common URL-safe replacement pattern, replace them after encoding:
'My clear text string'.StringToBase64.Replace('/','_').Replace('+','-')
Use this form only when the receiving system expects _ in place of / and - in place of +. The receiver must apply the corresponding interpretation before it decodes the Base64 value.
Convert clear text to a BLOB
If an API or operation needs the UTF-8 bytes of clear text rather than Base64 text, encode the string and then convert the Base64 result to a BLOB:
'My clear text string'.StringToBase64.Base64ToBlob
This pattern produces a UTF-8 byte array (BLOB). Use it, for example, when passing text into an operation that computes a hash from bytes. See HowTos:Convert String to Bytes for a complete example that builds a token and calculates a SHA512 hash.
Deflate-compressed tokens
Some protocols, including SAML token scenarios, expect data to be compressed with Deflate before it is sent. In Turnkey, use the Deflate mechanism available through SysSingleton.Deflate as required by the receiving protocol. Do not treat Base64 encoding as compression: encoding and Deflate compression are separate steps.
