Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 12:46, 7 September 2007.

Encrypt-Decrypt Messages

From Forum Nokia Wiki

Contents

Introduction

Short Messaging Service(SMS) is the heart of Mobile Device. SMS has gained popularity in the communication medium over the years. People generally do not share their private information in nature. Thus, messages are part of this so called private information. In some cases user may wish to encrypt-hide-delete his/her messages when his mobile device is out of reach to him. The following article is all about playing with such security features that can be enabled with messages.

Prerequisite

  • Download SmsHandler.zip from here: [SmsHander.Zip]
  • Extracting SmsHandler.zip will result into SmsHandler.h and SmsHandler.cpp
  • Copy-Paste SmsHandler.h into your project's /inc folder.
  • Copy-Paste SmsHandler.cpp into your project's /src folder.
  • Edit your .mmp file. Add an entry for SmsHandler.cpp in SOURCE directive.
SOURCE	SMSHandler.cpp
  • Edit your .mmp file. Add libraries for SMS handling.
//Libraries included for SMS support-
LIBRARY	msgs.lib smcm.lib gsmu.lib mtur.lib


  • Open your CYrApplicationContainer.h file.
  • Inlcude SmsHandler.h.
#include "SMSHandler.h" //Added for SMS Handling
  • Define an object of SmsHandler class.
private: //data
            .......
	.......
	CSmsHandler* iSmsHandler;


  • Open your CYrApplicationContainer.cpp file.
  • Initialize SmsHanlder object.
CYrApplicationContainer::Constructl()......
{
.....
.....
    SetRect(aRect);
    ActivateL();
 
    iSmsHandler = CSmsHandler::NewL(); // SmsHandler 
}

Encrypt Messages

The following code snippets illustrate the Encryption part of the messages.

Argument FieldToBeProcessed can be:

  • KMsvGlobalInBoxIndexEntryId
  • KMsvGlobalOutBoxIndexEntryId
  • KMsvDraftEntryId
  • KMsvSentEntryId
void CSmsHandler::EncryptAll(TMsvId FieldToBeProcessed)
{
	TBuf16<500> SMSContent;
 
	TMsvSelectionOrdering sort;
	sort.SetShowInvisibleEntries(ETrue); // we want to handle also the invisible entries
 
	CMsvEntry* inboxContext=CMsvEntry::NewL(*iSession,FieldToBeProcessed,sort);
	CleanupStack::PushL(inboxContext);
 
	CMsvEntrySelection* entries = inboxContext->ChildrenL();
	CleanupStack::PushL( entries );
 
	TInt msgCount= entries->Count();
	for (TInt i=0; i<entries->Count(); i++)
	{
 
		TMsvId entryID = entries->At(i);
		iSmsMtm->SwitchCurrentEntryL(entryID);
 
		CMsvEntry* entry= iSession->GetEntryL((*entries)[i]);
		CleanupStack::PushL(entry);
 
		TMsvEntry entry1 =  entry->Entry();
 
 		CMsvStore* inboxStore= entry->EditStoreL();
		CleanupStack::PushL(inboxStore);
 
 
		iSmsMtm->Entry().ChangeL( entry1 );
		if (inboxStore->HasBodyTextL())
		{
 
			TBufC<50> aText(entry1.iDetails);
			
			CRichText& RichText= iSmsMtm->Body();
			inboxStore->RestoreBodyTextL(RichText);
			const TInt length = RichText.DocumentLength();
 
			SMSContent.Copy(RichText.Read(0,length));
			Encrypt(SMSContent ); // Encrypt Message Body
 
			RichText.Reset();
			RichText.InsertL( 0 , SMSContent);
			inboxStore->StoreBodyTextL(RichText);
		
			TBuf16<20> PhoneNumber;
			PhoneNumber.Copy(aText);
			Encrypt( PhoneNumber ); // Encrypt Phone Number header of the Message
			entry1.iDescription.Set(SMSContent);
			entry1.iDetails.Set(PhoneNumber);
 
			iSmsMtm->Entry().ChangeL( entry1 );
			inboxStore->CommitL();
		}
		else
		{
		// no text in SMS 
		}
		CleanupStack::PopAndDestroy(inboxStore);
		CleanupStack::PopAndDestroy(entry);
	}
	CleanupStack::PopAndDestroy(entries);
	CleanupStack::PopAndDestroy(inboxContext);
}
void CSmsHandler:: Encrypt (TDes& val)
{
	for(TInt iCount=0; iCount< val.Length();iCount++)
	{
		val[iCount]+=5;
	}
}

Decrypt Messages

The following code snippets illustrate the reverse procedure of encryption which will let messages in original readable form.

Argument FieldToBeProcessed can be:

  • KMsvGlobalInBoxIndexEntryId
  • KMsvGlobalOutBoxIndexEntryId
  • KMsvDraftEntryId
  • KMsvSentEntryId
void CSmsHandler::DecryptAll(TMsvId FieldToBeProcessed)
{
	TBuf16<500> SMSContent;
 
	TMsvSelectionOrdering sort;
	sort.SetShowInvisibleEntries(ETrue); // we want to handle also the invisible entries
 
	CMsvEntry* inboxContext=CMsvEntry::NewL(*iSession,FieldToBeProcessed,sort);
	CleanupStack::PushL(inboxContext);
 
	CMsvEntrySelection* entries = inboxContext->ChildrenL();
	CleanupStack::PushL( entries );
 
	TInt msgCount= entries->Count();
	for (TInt i=0; i<entries->Count(); i++)
	{
 
		TMsvId entryID = entries->At(i);
		iSmsMtm->SwitchCurrentEntryL(entryID);
 
		CMsvEntry* entry= iSession->GetEntryL((*entries)[i]);
		CleanupStack::PushL(entry);
 
		TMsvEntry entry1 =  entry->Entry();
 
 		CMsvStore* inboxStore= entry->EditStoreL();
		CleanupStack::PushL(inboxStore);
 
 
		iSmsMtm->Entry().ChangeL( entry1 );
		if (inboxStore->HasBodyTextL())
		{
 
			TBufC<50> aText(entry1.iDetails);
			
			CRichText& RichText= iSmsMtm->Body();
			inboxStore->RestoreBodyTextL(RichText);
			const TInt length = RichText.DocumentLength();
 
			SMSContent.Copy(RichText.Read(0,length));
			Decrypt(SMSContent ); // Encrypt Message Body
 
			RichText.Reset();
			RichText.InsertL( 0 , SMSContent);
			inboxStore->StoreBodyTextL(RichText);
		
			TBuf16<20> PhoneNumber;
			PhoneNumber.Copy(aText);
			Decrypt( PhoneNumber ); // Encrypt Phone Number header of the Message
			entry1.iDescription.Set(SMSContent);
			entry1.iDetails.Set(PhoneNumber);
 
			iSmsMtm->Entry().ChangeL( entry1 );
			inboxStore->CommitL();
		}
		else
		{
		// no text in SMS 
		}
		CleanupStack::PopAndDestroy(inboxStore);
		CleanupStack::PopAndDestroy(entry);
	}
	CleanupStack::PopAndDestroy(entries);
	CleanupStack::PopAndDestroy(inboxContext);
}
void CSmsHandler:: Decrypt (TDes& val)
{
	for(TInt iCount=0; iCount< val.Length();iCount++)
	{
		val[iCount]-=5;
	}
}

Hide Messages

The following code snippets illustrate hiding messages for security purpose.

Argument FieldToBeProcessed can be:

  • KMsvGlobalInBoxIndexEntryId
  • KMsvGlobalOutBoxIndexEntryId
  • KMsvDraftEntryId
  • KMsvSentEntryId
void CSmsHandler::HideAll(TMsvId FieldToBeProcessed)
{
 
	TMsvSelectionOrdering sort;
	sort.SetShowInvisibleEntries(ETrue); // we want to handle also the invisible entries
 
	CMsvEntry* inboxContext=CMsvEntry::NewL(*iSession,FieldToBeProcessed,sort);
	CleanupStack::PushL(inboxContext);
 
	CMsvEntrySelection* entries = inboxContext->ChildrenL();
	CleanupStack::PushL( entries );
 
	TInt msgCount= entries->Count();
	for (TInt i=0; i<entries->Count(); i++)
	{
 
		TMsvId entryID = entries->At(i);
		iSmsMtm->SwitchCurrentEntryL(entryID);
 
		CMsvEntry* entry= iSession->GetEntryL((*entries)[i]);
		CleanupStack::PushL(entry);
 
		TMsvEntry entry1 =  entry->Entry();
 
 		CMsvStore* inboxStore= entry->EditStoreL();
		CleanupStack::PushL(inboxStore);
 
		entry1.SetVisible(EFalse);
 
		iSmsMtm->Entry().ChangeL( entry1 );
 
		CleanupStack::PopAndDestroy(inboxStore);
		CleanupStack::PopAndDestroy(entry);
	}
	CleanupStack::PopAndDestroy(entries);
	CleanupStack::PopAndDestroy(inboxContext);
}

Show Messages

The following code snippets illustrate reverse procedure of getting messages back in the "Show" mode.

Argument FieldToBeProcessed can be:

  • KMsvGlobalInBoxIndexEntryId
  • KMsvGlobalOutBoxIndexEntryId
  • KMsvDraftEntryId
  • KMsvSentEntryId
void CSmsHandler::ShowAll(TMsvId FieldToBeProcessed)
{
 
	TMsvSelectionOrdering sort;
	sort.SetShowInvisibleEntries(ETrue); // we want to handle also the invisible entries
 
	CMsvEntry* inboxContext=CMsvEntry::NewL(*iSession,FieldToBeProcessed,sort);
	CleanupStack::PushL(inboxContext);
 
	CMsvEntrySelection* entries = inboxContext->ChildrenL();
	CleanupStack::PushL( entries );
 
	TInt msgCount= entries->Count();
	for (TInt i=0; i<entries->Count(); i++)
	{
 
		TMsvId entryID = entries->At(i);
		iSmsMtm->SwitchCurrentEntryL(entryID);
 
		CMsvEntry* entry= iSession->GetEntryL((*entries)[i]);
		CleanupStack::PushL(entry);
 
		TMsvEntry entry1 =  entry->Entry();
 
 		CMsvStore* inboxStore= entry->EditStoreL();
		CleanupStack::PushL(inboxStore);
 
		entry1.SetVisible(ETrue);
 
		iSmsMtm->Entry().ChangeL( entry1 );
 
		CleanupStack::PopAndDestroy(inboxStore);
		CleanupStack::PopAndDestroy(entry);
	}
	CleanupStack::PopAndDestroy(entries);
	CleanupStack::PopAndDestroy(inboxContext);
}

Delete Messages

For more brutal force, you can delete messages from Messaging folders.

Argument FieldToBeProcessed can be:

  • KMsvGlobalInBoxIndexEntryId
  • KMsvGlobalOutBoxIndexEntryId
  • KMsvDraftEntryId
  • KMsvSentEntryId
void CSmsHandler::DeleteMessages()
{
	TMsvSelectionOrdering sort;
	sort.SetShowInvisibleEntries(ETrue); // we want to handle also the invisible entries
 
	CMsvEntry* inboxContext=CMsvEntry::NewL(*iSession,FieldToBeProcessed,sort);
	CleanupStack::PushL(inboxContext);
 
	CMsvEntrySelection* entries = inboxContext->ChildrenL();
	CleanupStack::PushL( entries );
 
	TInt msgCount= entries->Count();
	TInt i;
	for (i=0; i<entries->Count(); i++)
	{
		TMsvId entryID = entries->At(i);
		iSmsMtm->SwitchCurrentEntryL(entryID);
 
		CMsvEntry* entry= iSession->GetEntryL((*entries)[i]);
		CleanupStack::PushL(entry);
 
		entry->DeleteL(entries->At(i));
		CleanupStack::PopAndDestroy(entry);
	}
	CleanupStack::PopAndDestroy(entries);
	CleanupStack::PopAndDestroy(inboxContext);
}

See Also:

Related Discussions
Thread Thread Starter Forum Replies Last Post
Message Sending Failed in 6600 binayrungta General Messaging 3 2005-08-19 15:59
Is MTM UI the solution? mirmit Symbian Networking & Messaging 0 2007-04-16 11:00
copying a dll or exe to device araja General Symbian C++ 7 2007-11-22 19:39
iso-10646-ucs-2 in mms subject allblue_ General Messaging 5 2003-12-07 15:12
Moving SMS messages from old to new phone constable General Discussion 3 2003-04-15 15:23
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX
     
    
            
            RDF Facets:
            
            
                        qfnZuserE5ftagQSxfolderX
                        qfnZuserE5ftagQSxpop3X
                        qfnZuserE5ftagQSxprivateX