![](https://pdfstore-manualsonline.prod.a.ki/pdfasset/9/c4/9c4432ed-94b6-4f82-9d47-c9fb5f98b613/9c4432ed-94b6-4f82-9d47-c9fb5f98b613-bge9.png)
Chapter 6 Symmetric-Key Operations 211
Block Ciphers
Step 5: Final
Step 6: Destroy
Remember to destroy all objects and free up any allocated memory:
Decrypting
As in the “Introductory Example” on page 9, decrypting is similar to encrypting. Use
the same AI, password, and salt. Use the proper decrypting AM and call
B_DecryptInit, B_DecryptUpdate, and B_DecryptFinal.
unsigned int outputLenFinal;
if ((status = B_EncryptFinal
(pbEncrypter, encryptedData + outputLenUpdate,
&outputLenFinal, encryptedDataLen - outputLenUpdate,
(B_ALGORITHM_OBJ)NULL_PTR,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
B_DestroyKeyObject (&pbeKey);
B_DestroyAlgorithmObject (&pbEncrypter);
B_DestroyAlgorithmObject (&randomAlgorithm);
if (pbeKeyItem.data, 0, MAX_PW_LEN) {
T_memset (pbeKeyItem.data, 0, MAX_PW_LEN);
T_free (pbekeyItem.data);
pbeKeyItem.data = NULL_PTR;
}
if (encryptedData != NULL_PTR) {
T_memset (encryptedData, 0, encryptedDataLen);
T_free (encryptedData);
encryptedData = NULL_PTR;
}