RSA Security 5.2.2 manual Decrypting, If status = BEncryptUpdate

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 205
Image 205

Block Ciphers

if ((status = B_EncryptUpdate

(encryptionObject, encryptedData, &outputLenUpdate, encryptedDataLen, (unsigned char *)dataToEncrypt, dataToEncryptLen, (B_ALGORITHM_OBJ)NULL_PTR, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Step 5: Final

if ((status = B_EncryptFinal

(encryptionObject, encryptedData + outputLenUpdate, &outputLenFinal, encryptedDataLen - outputLenUpdate, (B_ALGORITHM_OBJ)NULL_PTR,

(A_SURRENDER_CTX *)NULL_PTR)) != 0) break;

Step 6: Destroy

Remember to destroy all objects that you created and free up any memory that you allocated:

B_DestroyKeyObject (&desKey);

B_DestroyAlgorithmObject (&encryptionObject);

B_DestroyAlgorithmObject (&randomAlgorithm);

T_free (encryptedData);

Note: Using T_free means you can no longer access the data at that address. Do not free a buffer until you no longer need the data it contains. If you will need the data later, you might want to save it to a file first.

Decrypting

As in the “Introductory Example” on page 9, decrypting is similar to encrypting. Use the same AI, IV, and key data. Use the proper decryption AM and call B_DecryptInit, B_DecryptUpdate, and B_DecryptFinal.

C h a p t e r 6 S y m m e t r i c - K e y O p e r a t i o n s

1 8 3

Page 205
Image 205
RSA Security 5.2.2 manual Decrypting, If status = BEncryptUpdate