Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:CBC mode encryption and decryption of data

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Needs-update.pngThis article needs to be updated: If you found this article useful, please fix the problems below then delete the {{ArticleNeedsUpdate}} template from the article to remove this warning.

Reasons: hamishwillee (10 May 2011)
SymbianCryptographyLibrary appears to be unavailable. Needs to be found, or if no longer available this article needs to be deleted.

Article Metadata
Code Example
Source file:
Tested with
Devices(s): Tested on Nokia N95, Nokia N78, Nokia E66
Keywords: CModeCBCEncryptor, CAESEncryptor
Created: User:Technical writer 1 (19 May 2009)
Last edited: hamishwillee (13 Sep 2012)



Cipher-block chaining (CBC) is an encryption mode where each block of plain text is XORed with the previous ciphertext block before being encrypted. This way, each ciphertext block is dependent on all plain text blocks processed up to that point. Also, to make each message unique, an initialisation vector must be used in the first block.


The class CModeCBCEncryptor, available in the Symbian Cryptography library, can be used for encryption of data. It is initialised with a subclass of CBlockTransformation, in this case CAESEncryptor, which it subsequently owns. The following code snippet shows how to encrypt and decrypt a block of data in CBC mode.


CBC mode encryption of data:

 void CCBCExAppUi::CBCEncryption(TPtr8& aDataPtr)
CAESEncryptor* aesEncryptor = CAESEncryptor::NewL(iCipherkey);
CModeCBCEncryptor* cbcEncryptor = CModeCBCEncryptor::NewLC(aesEncryptor, iIV);<br>
for(TInt i = 0; i<3; i++)
TPtr8 tempDataptr = aDataPtr.MidTPtr(16*i,16);

CBC mode decryption of data:

 void CCBCExAppUi::CBCDecryption(TPtr8& aDataPtr)
CAESDecryptor* aesdecryptor = CAESDecryptor::NewL(iCipherkey);
CModeCBCDecryptor* cbcDecryptor = CModeCBCDecryptor::NewLC(aesdecryptor, iIV);<br>
for(TInt i = 0; i<3; i++)
TPtr8 tempDataptr = aDataPtr.MidTPtr(16*i,16);

Example application

This page was last modified on 13 September 2012, at 06:21.
184 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.