![](https://pdfstore-manualsonline.prod.a.ki/pdfasset/9/c4/9c4432ed-94b6-4f82-9d47-c9fb5f98b613/9c4432ed-94b6-4f82-9d47-c9fb5f98b613-bgd3.png)
Chapter 6 Symmetric-Key Operations 189
Block Ciphers
Step 5: Final
Step 6: Destroy
Remember to destroy all objects created and free up any memory allocated:
if ((status = (encryptedData == NULL_PTR)) != 0)
break;
if ((status = B_EncryptUpdate
(rc2Encrypter, encryptedData, &outputLenUpdate,
encryptedDataLen, dataToEncrypt, dataToEncryptLen,
(B_ALGORITHM_OBJ)NULL_PTR,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
unsigned int outputLenFinal;
if ((status = B_EncryptFinal
(rc2Encrypter, encryptedData + outputLenUpdate,
&outputLenFinal, encryptedDataLen - outputLenUpdate,
(B_ALGORITHM_OBJ)NULL_PTR,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
B_DestroyKeyObject (&rc2Key);
B_DestroyAlgorithmObject (&rc2Encrypter);
B_DestroyAlgorithmObject (&randomAlgorithm);
if (encryptedData != NULL_PTR) {
T_memset (encryptedData, 0, encryptedDataLen);
T_free (encryptedData);
encryptedData = NULL_PTR;
}
if (rc2KeyItem.data != NULL_PTR) {
T_memset (rc2KeyItem.data, 0, rc2KeyItem.len);
T_free (rc2KeyItem.data);
rc2KeyItem.data = NULL_PTR;
rc2KeyItem.len = 0;
}