Please give me a solution for this its very......urgent.

Login to reply to this topic.
Thu, 2007-12-20 10:40
Joined: 2007-10-16
Forum posts: 65

Hai,
Please help me 2 solve this.In EncryptionContainer,Iam encrypting the contacts and writing the contacts to File using C File Operations and after that commiting the contacts to CContactDataBase.
In DecryptionContainer,Iam opening the File, reading the contacts, decrypting them and commiting the contacts to the DataBase .
After commiting the contacts to the DataBase,Iam facing a problem in PhoneBook,contacts are not commmiting correctly to the dataBase.Contacts are mixing means Iam able to see the 2nd contact fields in 1st contact and 3rd contact fields in 2nd contact,like that.All the contacts
fields are jumbled.

Iam posting the code.Pls see this and help me.Its very urgent requirement for me.

In EncryptionContainer.cpp

void CEncryptContactContainer::Encrypt()
{
//Open the default CContactDataBase
CContactDatabase *contactDB = CContactDatabase::OpenL();
CleanupStack::PushL(contactDB);

TContactIter iter(*contactDB);
TContactItemId aContactId;

const CContactIdArray* contactArray = contactDB->SortedItemsL();

//Get the count of contacts
TInt cnt=contactArray->Count();
FILE *pFile;
pFile = fopen ("File.txt","w");
       
for(TInt i=0;i<cnt;i++)
{
CContactItem* contactItem=NULL;
contactItem= contactDB->OpenContactL((*contactArray)[i]);
CleanupStack::PushL(contactItem);
               
CContactItemFieldSet& fieldSet= contactItem->CardFields();
//Get the count of fields
TInt fieldCount=fieldSet.Count(); // This will give number of contact fields.

for(TInt index=0; index < fieldCount; index++)
{
CContactItemField& field = fieldSet


;
const CContentType& type = field.ContentType();
if(!(type.ContainsFieldType(KUidContactFieldBirthday)))
{
//Get the Text of Filed of Contacts

TPtrC name = contactItem->CardFields()


.TextStorage()->Text();
TInt FieldTextLength = name.Length();
                                                         
HBufC8* buffer = HBufC8::NewLC(FieldTextLength);
buffer->Des().Copy(name);
                                                        
char* encryptdata = new char[100];
Mem::Copy(encryptdata, buffer->Ptr(), 100);
encryptdata[FieldTextLength] = '\0';
CleanupStack::PopAndDestroy(buffer);

int dwdatalength = 32;
//Using my own AES Algorithm
Encrypt((unsigned char*)encryptdata,dwDatalength,DKey);

//After Encryption write the data to File
if(pFile!=NULL)
{
fgets(encryptdata,100,pFile);
fputs(encryptdata,pFile);
fputs("\r\n",pFile);
}


TPtrC8 ptr(reinterpret_cast<const TUint8*>(encryptdata));
HBufC* buffer1 = NULL;
buffer1 = HBufC::NewL(ptr.Length());
buffer1->Des().Copy(ptr);

contactItem->CardFields()


.TextStorage()->SetTextL(buffer1);
}
} //Inner for loop ends here
contactDB->CommitContactL(*contactItem);
CleanupStack::PopAndDestroy(contactItem);
} //Outer for loop ends here
CleanupStack::PopAndDestroy(contactDB);
fclose(pFile);
}

In DecryptionContainer.cpp

void CDecryptContactContainer::Decryptl()
{
CContactDatabase *contactDB = CContactDatabase::OpenL();
CleanupStack::PushL(contactDB);

TContactIter iter(*contactDB);
TContactItemId aContactId;

const CContactIdArray* contactArray = contactDB->SortedItemsL();
TInt cnt=contactArray->Count();
FILE *pFile;
pFile = fopen ("File.txt","r");

for(TInt i=0;i<cnt;i++)
{
CContactItem* contactItem=NULL;

contactItem= contactDB->OpenContactL((*contactArray)[i]);
CleanupStack::PushL(contactItem);
               
CContactItemFieldSet& fieldSet= contactItem->CardFields();
Int fieldCount=fieldSet.Count(); // This will give number of contact fields.

for(TInt index=0; index < fieldCount; index++)
{
CContactItemField& field = fieldSet


;
const CContentType& type = field.ContentType();
if(!(type.ContainsFieldType(KUidContactFieldBirthday)))
{

char *encryptdata = new char[100];
if(pFile!=NULL)
{
fgets(encryptdata,100,pFile);
}


Decrypt((unsigned char*)encryptdata,dwDatalength,DKey);

TPtrC8 ptr(reinterpret_cast<const TUint8*>(encryptdata));
HBufC* buffer1 = NULL;
buffer1 = HBufC::NewL(ptr.Length());
buffer1->Des().Copy(ptr);

contactItem->CardFields()


.TextStorage()->SetTextL(buffer1);
}
} //Inner for loop ends here
contactDB->CommitContactL(*contactItem);
CleanupStack::PopAndDestroy(contactItem);
} //Outer for loop ends here
CleanupStack::PopAndDestroy(contactDB);
}

  • Login to reply to this topic.