chunk-encoding
- C
- C++
- CSharp
- Java
- JavaScript
- Swift
- Python
- Go
- PHP
/* Status. */
mte_status status;
/* Licensing. */
const char* company;
const char* license;
/* Suppress unused args. */
(void)argc;
(void)argv;
/* Initialize MTE. */
if (!mte_init(NULL, NULL))
{
fputs("MTE init error.", stderr);
return -1;
}
/* Initialize MTE license. If a license code is not required (e.g., trial
mode), this can be skipped. This demo attempts to load the license info
from the environment if required. */
if (!mte_license_init("YOUR_COMPANY", "YOUR_LICENSE"))
{
company = getenv("MTE_COMPANY");
license = getenv("MTE_LICENSE");
if (company == NULL || license == NULL ||
!mte_license_init(company, license))
{
fprintf(stderr, "License init error (%s): %s\n",
mte_base_status_name(mte_status_license_error),
mte_base_status_description(mte_status_license_error));
return mte_status_license_error;
}
}
/* Retrieve block size of the cipher. If greater than 1, this demo may not
work as expected. */
size_t block_size = mte_base_ciphers_block_bytes(MTE_CIPHER_ENUM);
if (block_size > 1)
{
printf("The block size must be set to 1.");
return 1;
}
/* Get the input data. */
printf("Enter the data to encode> ");
fflush(stdout);
(void)!fgets(input, sizeof(input), stdin);
input[strlen(input) - 1] = '\0';
input_bytes = (MTE_SIZE_T)strlen(input);
/* Get the personalization string. */
printf("Enter the personalization> ");
fflush(stdout);
(void)!fgets(personal, sizeof(personal), stdin);
personal[strlen(personal) - 1] = '\0';
mte_drbg_inst_info i_info = { &ei_cb, NULL, &n_cb, NULL, personal, 0 };
i_info.ps_bytes = (MTE_SIZE_T)strlen(personal);
/* Create the encoder. */
MTE_HANDLE encoder;
mte_mke_enc_init_info e_info = MTE_MKE_ENC_INIT_INFO_INIT(
MTE_DRBG_ENUM, MTE_TOKBYTES, MTE_VERIFIERS_ENUM,
MTE_CIPHER_ENUM, MTE_HASH_ENUM, NULL, NULL, NULL, NULL, NULL, NULL);
mte_enc_args e_args = MTE_ENC_ARGS_INIT(NULL, 0, NULL, &t_cb, NULL);
encoder = MTE_ALLOCA(mte_mke_enc_state_bytes(&e_info));
status = mte_mke_enc_state_init(encoder, &e_info);
if (status != mte_status_success)
{
fprintf(stderr, "Encoder init error (%s): %s\n",
mte_base_status_name(status),
mte_base_status_description(status));
return status;
}
status = mte_mke_enc_instantiate(encoder, &i_info);
if (status != mte_status_success)
{
fprintf(stderr, "Encoder instantiate error (%s): %s\n",
mte_base_status_name(status),
mte_base_status_description(status));
return status;
}
/* This sample works with the MKE add-on that uses a cipher block size of 1. Any other
cipher block sizes are not guaranteed to work.
The encryption and decryption chunk sizes can be the same or different. */
const size_t encrypt_chunk_size = 10;
/* Create buffer to hold encrypt chunk size. */
char* encrypt_chunk_buf;
encrypt_chunk_buf = malloc(encrypt_chunk_size);
/* Get the chunk state size requirement. */
size_t enc_buff_bytes = mte_mke_enc_encrypt_state_bytes(encoder);
/* Create buffer to hold MTE encryption state. */
unsigned char* mke_encryption_state_buffer;
mke_encryption_state_buffer = malloc(enc_buff_bytes);
/* Start chunking session. */
status = mte_mke_enc_encrypt_start(encoder, mke_encryption_state_buffer);
if (status != mte_status_success)
{
fprintf(stderr, "Error starting encryption: (%s): %s\n",
mte_base_status_name(status),
mte_base_status_description(status));
return status;
}
/* Create buffer to hold the encoded result. */
char* encoded_input = malloc(1);
mte_enc_args encoding_args = MTE_ENC_ARGS_INIT(NULL, 0, NULL, &t_cb, NULL);
/* Loop through input one chunk at a time. */
size_t amount_encoded = 0;
while (amount_encoded < input_bytes)
{
/* Encrypt a chunk of the input to the encrypt chunk buffer. Use encrypt chunk size, or the size of the input, whichever is smaller. */
MTE_SET_ENC_IO(encoding_args, input + amount_encoded, min(encrypt_chunk_size, input_bytes - amount_encoded), encrypt_chunk_buf);
status = mte_mke_enc_encrypt_chunk(encoder, mke_encryption_state_buffer, &encoding_args);
if (status != mte_status_success)
{
fprintf(stderr, "Error encrypting chunk: Status: %s/%s\n",
mte_base_status_name(status),
mte_base_status_description(status));
return status;
}
/* Check if there were more than 0 bytes encoded. Zero bytes does not
mean there is an error, just that there is not anything to write for this pass. */
if (encoding_args.bytes > 0)
{
/* Reallocate the encoded input buffer to fit the size of how much has already been encrypted. */
encoded_input = realloc(encoded_input, amount_encoded + encoding_args.bytes);
/* Copy the encoded result to the buffer. */
memcpy(encoded_input + amount_encoded, encoding_args.encoded, encoding_args.bytes);
/* Add the size of the encoded amount to the total amount. */
amount_encoded = amount_encoded + encoding_args.bytes;
}
}
/* Finish the encryption with the encryption buffer.
If the original input is short enough, this finish call can be much larger than original input size. */
MTE_SET_ENC_IO(encoding_args, NULL, 0, NULL);
status = mte_mke_enc_encrypt_finish(encoder, mke_encryption_state_buffer, &encoding_args);
if (status != mte_status_success)
{
fprintf(stderr, "Error finishing encryption: (%s): %s\n",
mte_base_status_name(status),
mte_base_status_description(status));
return status;
}
/* This will include any bytes left over from the input, as well as data needed by the decryption engine. */
if (encoding_args.bytes > 0)
{
/* Reallocate the encoded input buffer to fit the size of how much has already been encrypted. */
encoded_input = realloc(encoded_input, amount_encoded + encoding_args.bytes);
/* Copy the encoded result to the buffer. */
memcpy(encoded_input + amount_encoded, encoding_args.encoded, encoding_args.bytes);
/* Add the size of the encoded amount to the total amount. */
amount_encoded = amount_encoded + encoding_args.bytes;
}
// Status.
mte_status status;
// Licensing.
const char* company;
const char* license;
/* Suppress unused args. */
(void)argc;
(void)argv;
// Initialize MTE license. If a license code is not required (e.g., trial
// mode), this can be skipped. This demo attempts to load the license info
// from the environment if required.
if (!MteBase::initLicense("YOUR_COMPANY", "YOUR_LICENSE"))
{
company = getenv("MTE_COMPANY");
license = getenv("MTE_LICENSE");
if (company == NULL || license == NULL ||
!MteBase::initLicense(company, license))
{
std::cerr << "License init error ("
<< MteBase::getStatusName(mte_status_license_error)
<< "): "
<< MteBase::getStatusDescription(mte_status_license_error)
<< std::endl;
return mte_status_license_error;
}
}
// Retrieve block size of the cipher. If greater than 1, this demo may not
// work as expected.
size_t blockSize = MteBase::getCiphersBlockBytes(MTE_CIPHER_ENUM);
if (blockSize > 1)
{
std::cout << "The block size must be set to 1." << std::endl;
return 1;
}
// Get the input data.
std::cout << "Enter the data to encode> ";
std::getline(std::cin, input);
inputBytes = input.length();
// Convert input to void pointer to pass in to encrypt chunk function.
void* inputVoidPointer = static_cast<char*>(malloc(inputBytes));
memcpy(inputVoidPointer, input.c_str(), inputBytes);
// Get the personalization string.
std::cout << "Enter the personalization> ";
std::getline(std::cin, personal);
// Create the callbacks to get entropy, nonce, and timestamp from stdin.
Cbs cbs;
// Create the encoder.
MteMkeEnc encoder;
encoder.setEntropyCallback(&cbs);
encoder.setNonceCallback(&cbs);
encoder.setTimestampCallback(&cbs);
status = encoder.instantiate(personal);
if (status != mte_status_success)
{
std::cerr << "Encoder instantiate error ("
<< MteBase::getStatusName(status)
<< "): "
<< MteBase::getStatusDescription(status)
<< std::endl;
return status;
}
// This sample works with the MKE add-on that uses a cipher block size of 1. Any other
// cipher block sizes are not guaranteed to work.
// The encryption and decryption chunk sizes can be the same or different.
const size_t encryptChunkSize = 10;
// Create buffer to hold the encoded result.
char* encodedInput = static_cast<char*>(malloc(1));
// Create buffer to hold encrypt chunk size.
char* encryptChunkBuf = static_cast<char*>(malloc(encryptChunkSize));
// Start chunking session.
status = encoder.startEncrypt();
if (status != mte_status_success)
{
std::cerr << "Error starting encryption: ("
<< MteBase::getStatusName(status)
<< "): "
<< MteBase::getStatusDescription(status)
<< std::endl;
return status;
}
// Loop through input one chunk at a time.
size_t amountEncoded = 0;
while (amountEncoded < inputBytes)
{
// Encrypt a chunk of the input to the encrypt chunk buffer. Use encrypt chunk size, or the size of the input, whichever is smaller.
// Note that the input will get overwritten with the encoded result.
size_t minAmount = std::min(encryptChunkSize, inputBytes - amountEncoded);
status = encoder.encryptChunk(static_cast<char*>(inputVoidPointer) + amountEncoded, minAmount);
if (status != mte_status_success)
{
std::cerr << "Error encrypting chunk: ("
<< MteBase::getStatusName(status)
<< "): "
<< MteBase::getStatusDescription(status)
<< std::endl;
return status;
}
// Reallocate the encoded input buffer to fit the size of what needs to be encoded.
encodedInput = static_cast<char*>(realloc(encodedInput, amountEncoded + minAmount));
// Copy the encoded result to the buffer. Note that earlier, this is the same as the original input.
memcpy(encodedInput + amountEncoded, static_cast<char*>(inputVoidPointer) + amountEncoded, minAmount);
// Add the size of the encoded amount to the total amount.
amountEncoded += minAmount;
}
// Finish the encryption with the encryption buffer.
// If the original input is short enough, this finish call can be much larger than original input size.
size_t finishBytes;
const void* finishBuffer = encoder.finishEncrypt(finishBytes, status);
if (status != mte_status_success)
{
std::cerr << "Error finishing encryption: ("
<< MteBase::getStatusName(status)
<< "): "
<< MteBase::getStatusDescription(status)
<< std::endl;
return status;
}
// This will include any bytes left over from the input, as well as data needed by the decryption engine.
if (finishBytes > 0)
{
// Reallocate the encoded input buffer to fit the size of what needs to be encoded.
encodedInput = static_cast<char*>(realloc(encodedInput, amountEncoded + finishBytes));
// Copy the encoded result to the buffer.
memcpy(encodedInput + amountEncoded, finishBuffer, finishBytes);
// Add the size of the encoded amount to the total amount.
amountEncoded += finishBytes;
}
//---------------------------------------
// Create MTE MKE Encoder as shown above
//---------------------------------------
// Initialize chunking session
MteStatus encoderStatus = mkeEncoder.StartEncrypt();
if(encoderStatus != MteStatus.mte_status_success)
{
// MTE was not successful so handle failure appropriately
// Below is only an example
throw new Exception("Failed to start encode chunk. Status: "
+ mkeEncoder.GetStatusName(encoderStatus)+ " / "
+ mkeEncoder.GetStatusDescription(encoderStatus));
}
//---------------------------------------------------------
// For each chunk of data one of two options are available
//---------------------------------------------------------
// When the byte[] buffer that is passed in is NOT the size of
// the amount of data inside of it use the full method
// encryptChunk(byte[] dataToBeEncoded, int offset, int sizeOfDataToBeEncoded)
//--------------------
// Option one
//--------------------
// byteData --> contains data to be Encoder
// 0 --> starting position
// byteData.Length --> length of the actual byte data
MteStatus chunkStatus = mkeEncoder.EncryptChunk(byteData, 0, byteData.Length);
if(chunkStatus != MteStatus.mte_status_success)
{
// Encode chunk unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
throw new Exception("Failed to encode chunk. Status: "
+ mkeEncoder.GetStatusName(chunkStatus)+ " / "
+ mkeEncoder.GetStatusDescription(chunkStatus));
}
//--------------------
// Option two
//--------------------
// When the byte[] is the exact size of the data inside this may be called
MteStatus chunkStatus = mkeEncoder.EncryptChunk(byteData);
if(chunkStatus != MteStatus.mte_status_success)
{
// Encode chunk unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
throw new Exception("Failed to encode chunk. Status: "
+ mkeEncoder.GetStatusName(chunkStatus)+ " / "
+ mkeEncoder.GetStatusDescription(chunkStatus));
}
// Once all data has been processed call finish method
// This method will ALWAYS have additional data that will need to be included
byte[] finalEncodedChunk = mkeEncoder.FinishEncrypt(out MteStatus finishStatus);
if(finishStatus != MteStatus.mte_status_success)
{
// Encode finish unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
throw new Exception("Failed to finish encode chunk. Status: "
+ mkeEncoder.GetStatusName(finishStatus)+ " / "
+ mkeEncoder.GetStatusDescription(finishStatus));
}
//---------------------------------------
// Create MTE MKE Encoder as shown above
//---------------------------------------
// Initialize chunking session
MteStatus encoderStatus = mkeEncoder.startEncrypt();
if(encoderStatus != MteStatus.mte_status_success)
{
// MTE was not successful so handle failure appropriately
// Below is only an example
throw new Exception("Failed to start encode chunk. Status: "
+ MteBase.getStatusName(encoderStatus)+ " / "
+ MteBase.getStatusDescription(encoderStatus));
}
//---------------------------------------------------------
// For each chunk of data one of two options are available
//---------------------------------------------------------
// When the byte[] that is passed in is NOT the size of
// the amount of data inside of it use the full method
// encryptChunk(byte[] dataToBeEncoded, int offset, int sizeOfDataToBeEncoded)
//--------------------
// Options one
//--------------------
// byteData --> contains data to be Encoder
// 0 --> starting position
// byteData.Length --> length of the actual byte data
MteStatus chunkStatus = mkeEncoder.encryptChunk(byteData, 0, byteDataSize);
if(chunkStatus != MteStatus.mte_status_success)
{
// Encode chunk unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
throw new Exception("Failed to encode chunk. Status: "
+ MteBase.getStatusName(chunkStatus)+ " / "
+ MteBase.getStatusDescription(chunkStatus));
}
//--------------------
// Options two
//--------------------
// When the byte[] is the exact size of the data inside this may be called
MteStatus chunkStatus = mkeEncoder.encryptChunk(byteData);
if(chunkStatus != MteStatus.mte_status_success)
{
// Encode chunk unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
throw new Exception("Failed to encode chunk. Status: "
+ MteBase.getStatusName(chunkStatus)+ " / "
+ MteBase.getStatusDescription(chunkStatus));
}
// Once all data has been processed call finish method
// This method will ALWAYS have additional data that will need to be included
MteBase.ArrStatus finalEncodedChunk = mkeEncoder.finishEncrypt();
if(finalEncodedChunk.status != MteStatus.mte_status_success)
{
// Encode finish unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
throw new Exception("Failed to finish encode chunk. Status: "
+ MteBase.getStatusName(finalEncodedChunk.status)+ " / "
+ MteBase.getStatusDescription(finalEncodedChunk.status));
}
//---------------------------------------
// Create MTE MKE Encoder as shown above
//---------------------------------------
// Initialize chunking session
const encoderStatus = mkeEncoder.startEncrypt();
if (encoderStatus !== MteStatus.mte_status_success) {
// MTE start chunking was not successful, handle failure appropriately
// Below is only an example
const status = mteBase.getStatusName(encoderStatus);
const message = mteBase.getStatusDescription(encoderStatus);
throw new Error(
`Failed to start encode chunk. Status: \n${status}: ${message}`,
);
}
// byteData --> contains data to be Encoded
const chunkStatus = mkeEncoder.encryptChunk(byteData);
if (chunkStatus !== MteStatus.mte_status_success) {
// Encode chunk unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
const status = mteBase.getStatusName(chunkStatus);
const message = mteBase.getStatusDescription(chunkStatus);
throw new Error(`Failed to encode chunk. Status: \n${status}: ${message}`);
}
// Once all data has been processed call finish method
// This method will ALWAYS have additional data that will need to be included
const finalEncodedChunk = mkeEncoder.finishEncrypt();
if (finalEncodedChunk.status !== MteStatus.mte_status_success) {
// Encode finish unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
const status = mteBase.getStatusName(finalEncodedChunk.status);
const message = mteBase.getStatusDescription(finalEncodedChunk.status);
throw new Error(
`Failed to finish encode chunk. Status: \n${status}: ${message}`,
);
}
// Status.
var status: mte_status
// Initialize MTE license. If a license code is not required (e.g., trial
// mode), this can be skipped.
if !MteBase.initLicense("LicenseCompanyName", "LicenseKey") {
let company = ProcessInfo.processInfo.environment["LicenseCompanyName"]
let license = ProcessInfo.processInfo.environment["LicenseKey"];
if company == nil || license == nil ||
!MteBase.initLicense(company!, license!) {
status = mte_status_license_error
print("License init error (\(MteBase.getStatusName(status))): " +
MteBase.getStatusDescription(status))
return Int32(status.rawValue)
}
}
// Retrieve block size of the cipher. If greater than 1, this demo may not
// work as expected.
let blockSize = MteBase.getCiphersBlockBytes(MteBase.getDefaultCipher())
if (blockSize > 1)
{
print("The chunk size must be set to 1.")
return 1
}
// Get the input data.
print("Enter the data to encode> ")
let input = readLine(strippingNewline: true) ?? ""
let inputBytes = input.count
// Create array of original input that will get encrypted.
var inputArray: [UInt8] = Array(input.utf8)
// Get the personalization string.
print("Enter the personalization>")
let personal = readLine(strippingNewline: true) ?? ""
// Create the callbacks to get entropy, nonce, and timestamp from stdin.
let cbs = Cbs()
// Create the encoder.
let encoder = try! MteMkeEnc()
encoder.setEntropyCallback(cbs)
encoder.setNonceCallback(cbs)
encoder.setTimestampCallback(cbs)
status = encoder.instantiate(personal)
if status != mte_status_success {
print("Encoder instantiate error (\(MteBase.getStatusName(status))): " +
MteBase.getStatusDescription(status))
return Int32(status.rawValue)
}
// The encryption and decryption chunk sizes can be the same or different.
let encryptChunkSize: size_t = 10
// Start chunking session.
status = encoder.startEncrypt()
if status != mte_status_success {
print("Error starting encryption (\(MteBase.getStatusName(status))): " +
MteBase.getStatusDescription(status))
return Int32(status.rawValue)
}
// Loop through input one chunk at a time.
var amountEncoded = 0
while (amountEncoded < inputBytes) {
// Encrypt a chunk of the input to the encrypt chunk buffer. Use encrypt chunk size, or the size of the input, whichever is smaller.
// Note that the input will get overwritten with the encoded result.
let minAmount = min(encryptChunkSize, inputBytes - amountEncoded)
status = encoder.encryptChunk(&inputArray, amountEncoded, minAmount)
if status != mte_status_success {
print("Error encrypting chunk (\(MteBase.getStatusName(status))): " +
MteBase.getStatusDescription(status))
return Int32(status.rawValue)
}
// Add the size of the encoded amount to the total amount.
amountEncoded += minAmount
}
// Finish the encryption.
// If the original input is short enough, this finish call can be much larger than original input size.
// Append the result to the input array.
let finishBuffer = encoder.finishEncrypt()
status = finishBuffer.status
if status != mte_status_success {
print("Error finishing encryption (\(MteBase.getStatusName(status))): " +
MteBase.getStatusDescription(status))
return Int32(status.rawValue)
}
// This will include any bytes left over from the input, as well as data needed by the decryption engine.
// Append the encoded finish results to the input array.
inputArray.append(contentsOf: finishBuffer.encoded)
amountEncoded += finishBuffer.encoded.count
#---------------------------------------
# Create MTE MKE Encoder as shown above
#---------------------------------------
# Initialize the chunking session
encoder_status = mke_encoder.start_encrypt()
if encoder_status != MteStatus.mte_status_success:
# MTE was not successful so handle failure appropriately.
# Below is only an example.
raise Exception("Failed to start encode chunk. Status: {0} / {1}\n".format(MteBase.get_status_name(encoder_status),
MteBase.get_status_description(encoder_status)))
#------------------------------------------------------
# Pass each chunk of data into the encrypt_chunk method.
# The data is encoded in place and the encoded data
# will replace the data put in the method
# IMPORTANT - The data length must be a multiple of the chosen ciphers block size.
chunk_status = mke_encoder.encrypt_chunk(byte_data)
if chunk_status != MteStatus.mte_status_success:
# Encode chunk unsuccessful and cannot continue, handle failure appropriately.
# Below is only an example.
raise Exception("Failed to encode chunk. Status: {0} / {1}\n".format(MteBase.get_status_name(chunk_status),
MteBase.get_status_description(chunk_status)))
# Once all data has been processed call finish method.
# This method will ALWAYS have additional data that will need to be included.
final_encoded_chunk,finish_status = mke_encoder.finish_encrypt()
if finish_status != MteStatus.mte_status_success:
# Encode finish unsuccessful and cannot continue, handle failure appropriately.
# Below is only an example.
raise Exception("Failed to finish encode chunk. Status: {0} / {1}\n".format(MteBase.get_status_name(finish_status),
MteBase.get_status_description(finish_status)))
//---------------------------------------
// Create MTE MKE Encoder as shown above
//---------------------------------------
// Initialize chunking session
encoderstatus := mkeEncoder.StartEncrypt()
if encoderstatus != mte.Status_mte_status_success {
// Handle error appropriately
// Example below
fmt.Fprintf(os.Stderr, "MTE Encoder StartEncrypt error (%v): %v\n",
mte.GetStatusName(encoderstatus), mte.GetStatusDescription(encoderstatus))
retcode = int(encoderstatus)
return
}
//------------------------------------------------------
// pass each chunk of data into the EncryptChunk method
// the data is encoded in place and the encoded data
// will replace the data put in the method
encoderStatus := mkeEncoder.EncryptChunk(byteData);
if encoderstatus != mte.Status_mte_status_success {
// Handle error appropriately
// Example below
fmt.Fprintf(os.Stderr, "MTE Encoder chunk error (%v): %v\n",
mte.GetStatusName(encoderstatus), mte.GetStatusDescription(encoderstatus))
retcode = int(encoderstatus)
return
}
// Once all data has been processed call finish method
// This method will ALWAYS have additional data that will need to be included
finalEncodedChunk, encodeStatus := encoder.FinishEncrypt()
if encodeStatus != mte.Status_mte_status_success {
// Handle error appropriately
// Example below
fmt.Fprintf(os.Stderr, "Encode finish error (%v): %v\n",
mte.GetStatusName(encodeStatus), mte.GetStatusDescription(encodeStatus))
break
}
<?php
//---------------------------------------
// Create MTE MKE Encoder as shown above
//---------------------------------------
// Initialize chunking session
$encoderStatus = $mkeEncoder->startEncrypt();
if(constant($encoderStatus) != mte_status_success)
{
// MTE was not successful so handle failure appropriately
// Below is only an example
throw new Exception("Failed to start encode chunk. Status: "
.$mkeEncoder->getStatusName(constant($encoderStatus))+ " / "
.$mkeEncoder->getStatusDescription(constant($encoderStatus));
}
//---------------------------------------------------------
// For each chunk of data process using encryptChunk
//---------------------------------------------------------
?>
<?php
// Process the chunk of data
$chunkStatus = $mkeEncoder->encryptChunk($data);
if(constant($chunkStatus["status"]) != mte_status_success)
{
// Encode chunk unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
throw new Exception("Failed to encode chunk. Status: "
.$mkeEncoder->getStatusName(constant($chunkStatus["status"]))+ " / "
.$mkeEncoder->getStatusDescription(constant($chunkStatus["status"])));
}
$encodedString .= $chunkStatus["str"];
?>
<?php
// Once all data has been processed call finish method
// This method will ALWAYS have additional data that will need to be included
$finalEncodedChunk = $mkeEncoder->finishEncrypt();
if(constant($finalEncodedChunk["status"]) != mte_status_success)
{
// Encode finish unsuccessful and cannot continue, handle failure appropriately
// Below is only an example
throw new Exception("Failed to finish encode chunk. Status: "
.$mkeEncoder->getStatusName(constant($finalEncodedChunk["status"]))+ " / "
.$mkeEncoder->getStatusDescription(constant($finalEncodedChunk["status"])));
}
if(strlen($finalEncodedChunk["str"]) > 0){
$encodedString .= $finalEncodedChunk["str"];
}
?>