Skip to main content

encoder-encode-data

// Fixed length must be at least as long as the largest expected input size.
// Padding will be added to the input if necessary so they are always the same size.

// Example values to be encoded.
string inputString = "What I want to be encoded goes here";
byte[] bytesToBeEncoded = Encoding.ASCII.GetBytes(inputString);

// Create MteStatus variable.
MteStatus encoderStatus;

// Below are 4 different examples of how to encode.
// ONLY ONE needs to be used.
// Encode byte[] to a base64 string
string encodedBytesAsString = flenEncoder.EncodeB64(bytesToBeEncoded, out encoderStatus);
if(encoderStatus != MteStatus.mte_status_success)
{
// Handle encode failure appropriately
// Below is only an example
throw new Exception("Failed to encode. Status: "
+ flenEncoder.GetStatusName(encoderStatus)+ " / "
+ flenEncoder.GetStatusDescription(encoderStatus));
}
// Encode string to a base64 string
string encodedStringAsString = flenEncoder.EncodeB64(inputString, out encoderStatus);
if(encoderStatus != MteStatus.mte_status_success)
{
// Handle encode failure appropriately
// Below is only an example
throw new Exception("Failed to encode. Status: "
+ flenEncoder.GetStatusName(encoderStatus)+ " / "
+ flenEncoder.GetStatusDescription(encoderStatus));
}
// Encode byte[] to a byte[]
byte[] encodedBytesAsBytes = flenEncoder.Encode(bytesToBeEncoded, out encoderStatus);
if(encoderStatus != MteStatus.mte_status_success)
{
// Handle encode failure appropriately
// Below is only an example
throw new Exception("Failed to encode. Status: "
+ flenEncoder.GetStatusName(encoderStatus)+ " / "
+ flenEncoder.GetStatusDescription(encoderStatus));
}
// Encode string to a byte[]
byte[] encodedStringAsBytes = flenEncoder.Encode(inputString, out encoderStatus);
if(encoderStatus != MteStatus.mte_status_success)
{
// Handle encode failure appropriately
// Below is only an example
throw new Exception("Failed to encode. Status: "
+ flenEncoder.GetStatusName(encoderStatus)+ " / "
+ flenEncoder.GetStatusDescription(encoderStatus));
}