Skip to main content

decoder-create

// Create MTE MKE Decoder with defaults
MteMkeDec mkeDecoder = new MteMkeDec();

// Need entropy, nonce and personalization string
// *** IMPORTANT NOTE ***
// Entropy is critical to security and should be created and
// handled like encryption keys. To permit decoding of encoded
// value, Encoder and Decoder must use identical Entropy, Nonce and
// Personalization String as well as Options . See Developer Guides for more information.
//-----------------------------------------------------------------
// The following personalization string and nonce values are for
// demonstration only and should not be used in a production environment
string personalizationString = "MySecretPersonalizationStringGoesHere";
long nonce = 12345678;

// Check how long of entropy we need.
// This example fills entropy with at string of zeros
// this should NOT be used in a production environment
int entropyMinBytes = mkeDecoder.GetDrbgsEntropyMinBytes(mkeDecoder.GetDrbg());
string entropy = (entropyMinBytes > 0)
? new String('0', entropyMinBytes)
: string.Empty;

// Set Decoder entropy and nonce
mkeDecoder.SetEntropy(Encoding.UTF8.GetBytes(entropyString));
mkeDecoder.SetNonce(nonce);

// Initialize MTE Decoder
MteStatus decoderStatus = mkeDecoder.Instantiate(personalizationString);
if(decoderStatus !=MteStatus.mte_status_success)
{
// MTE cannot continue so handle failure appropriately
// Below is an Example
throw new ApplicationException($"Failed to initialize the MTE Decoder engine." +
$"Status: {mkeDecoder.GetStatusName(decoderStatus)} / " +
$"{mkeDecoder.GetStatusDescription(decoderStatus)}");
}