🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Convert String to Bytes
This page was created by Wikiadmin on 2026-07-29. Last edited by Wikiadmin on 2026-07-29.

You can convert clear-text strings to UTF-8 byte arrays (BLOBs) in OCL or EAL when an API, hash operation, or binary REST endpoint needs bytes rather than text.

Convert a string to a UTF-8 BLOB

Use StringToBase64 followed by Base64ToBlob:

'My clear text string'.StringToBase64.Base64ToBlob

This expression performs two steps:

  1. StringToBase64 encodes the string as UTF-8 and represents those bytes as Base64 text.
  2. Base64ToBlob decodes that Base64 text into a BLOB (byte array).

For example, use the expression below as the input to a hash operation when the hash function requires a BLOB:

'content to hash'.StringToBase64.Base64ToBlob

Do not stop at StringToBase64 when the receiving operation expects bytes. That operation returns a Base64 string, while Base64ToBlob returns the byte array.

Choose the required encoding

The conversion above is appropriate when the other system requires UTF-8. If an integration specifies another character encoding, use the .NET Encoding class instead. See GetBytes and Encoding.

Encoding.ASCII.GetBytes('Example text')

The encoding changes the resulting bytes. Agree the encoding with the receiving system before calculating a hash, signature, or request body.

Requirement Use
UTF-8 bytes as a BLOB 'text'.StringToBase64.Base64ToBlob
Bytes in a named .NET encoding Encoding.<EncodingName>.GetBytes('text')
UTF-8 bytes represented as Base64 text 'text'.StringToBase64
Windows-1252 (ANSI) bytes represented as Base64 text StringToAnsiBase64
A specified code-page encoding represented as Base64 text StringToEncodedBase64

Example: calculate a SHA-512 token

The following OCL expression constructs a value from requestbody, a merchant secret, and timestamp. It converts that value to UTF-8 bytes, calculates a SHA-512 hash, converts the hash bytes to a hyphen-separated string, removes the hyphens, and prefixes the merchant ID. The final result is Base64 text.

let orgdata=requestbody+SveaSettingsSingleton.oclSingleton.MerchantSecret+timestamp in
(
  let thehash=SysSingleton.oclSingleton.SHA512ComputeHash(orgdata.StringToBase64.Base64ToBlob) in
  (
    (SveaSettingsSingleton.oclSingleton.MerchantId+':'+SysSingleton.oclSingleton.BitConverterToString( thehash ).Replace('-','')).StringToBase64
  )
)

The expression relies on these stages:

  1. orgdata is the concatenated clear-text value that will be hashed.
  2. orgdata.StringToBase64.Base64ToBlob supplies its UTF-8 bytes to SHA512ComputeHash.
  3. SHA512ComputeHash returns the hash as a BLOB.
  4. BitConverterToString renders the hash bytes in a string such as 01-A0-FF; Replace('-',) removes its separators.
  5. The merchant ID and hexadecimal hash are joined with :, then encoded with StringToBase64 for the final token value.

Use the exact concatenation order, encoding, hash algorithm, separator handling, and final representation required by the external service. A change to any one of these produces a different token.

For the available SHA-512, SHA-256, and byte-array formatting operations, see SHA512ComputeHash, SHA256ComputeHash and BitConverterToString. If you need to accept a binary request body in a REST ViewModel, see Expose REST Service.

See also