Skip to main content

chunk-encoding

//---------------------------------------
// 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));
}