Encryption and decryption of a password

Login to reply to this topic.
Wed, 2007-11-21 13:07
Joined: 2007-10-26
Forum posts: 36

How to write a code to set a pssword for mobile, and to encrypt and decrypt the password which has been set?


Wed, 2007-11-21 14:37
Joined: 2004-05-24
Forum posts: 981
Re: Encryption and decryption of a password

What exactly do you mean? Do you want to encrypt a string? Or?


pirosl

Wed, 2007-11-21 14:43
Joined: 2007-10-26
Forum posts: 36
Re: Encryption and decryption of a password

Yes I want to encrypt and decrypt and set a password conatining string only.

It is well and good if it can do all type of pws.

Thanks 4 reply

Wed, 2007-11-21 15:27
Joined: 2004-05-24
Forum posts: 981
Re: Encryption and decryption of a password

What sdk are you using? Can't you use Symbian Cryptography library?
See this link: http://www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/N1010A/Crypto/cryptography.overview.html


pirosl

Thu, 2007-11-22 10:25
Joined: 2007-10-26
Forum posts: 36
Re: Encryption and decryption of a password

yes I have tried all these ,now Iam sending my code please modify it. Its not working exactly.
void CPasswordAppUi::HandleCommandL(TInt aCommand)
{
switch(aCommand)
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;

case EPasswordCommand1:
PasswordL();
break;

case EPasswordCommand2:
ConfirmpwL();
break;

default:
Panic(EPasswordBasicUi);
break;
}
}


void CPasswordAppUi::PasswordL()
{
TBuf<20> password;
CAknTextQueryDialog* dlg1 =
CAknTextQueryDialog::NewL(password);



if (!dlg1->ExecuteLD(R_DIALOG_PASSWORD_QUERY))
{
return;
}


RFs fileSession;
User::LeaveIfError(fileSession.Connect());
CleanupClosePushL(fileSession);
RFile file;
if (file.Replace(fileSession, KPWFile, EFileWrite) != KErrNone)
{
CAknInformationNote* informationNote = new (ELeave)CAknInformationNote;

_LIT(KCreateFailedMessage,"Failed to create cipher.enc");
informationNote->ExecuteLD(KCreateFailedMessage);
CleanupStack::PopAndDestroy(); // Close fileSession
return;
}
CleanupClosePushL(file);

CBoundedSecurityBase* encrypter = Security::NewL();
CleanupStack::PushL(encrypter);
encrypter->SetL(KNullDesC, password);


CleanupStack::PopAndDestroy(); // Close outputFileStream
CleanupStack::PopAndDestroy(encrypter);
CleanupStack::PopAndDestroy(); // Close file
CleanupStack::PopAndDestroy(); // Close fileSession;
}

void CPasswordAppUi::ConfirmpwL()
{
//TInt err;
TBuf<20> password;
CAknTextQueryDialog* dlg2 = new (ELeave) CAknTextQueryDialog(password);
if (! dlg2->ExecuteLD(R_DIALOG_PASSWORD_QUERY))
{
return;
}

// Open file containing encrypted data
RFs fileSession;
User::LeaveIfError(fileSession.Connect());
CleanupClosePushL(fileSession);
RFile file;
User::LeaveIfError(file.Open(fileSession, KPWFile, EFileRead));
CleanupClosePushL(file);

RFileReadStream inputFileStream(file);
CleanupClosePushL(inputFileStream);

//inputFileStream>>Text1;
CAknInformationNote* note = new (ELeave)CAknInformationNote;
note->ExecuteLD(Text1);

// Read the security data
HBufC8* securityData = HBufC8::NewL(inputFileStream,KAknExQueryTextBufLength);

// Create security object, using the read security data
CBoundedSecurityBase* decrypter = Security::NewL(*securityData);
CleanupStack::PushL(decrypter);

// Authenticate password

//TRAPD(err,decrypter->PrepareL(password));

//
if (err != KErrNone)
{
CAknInformationNote* informationNote = new (ELeave)CAknInformationNote;

_LIT(KPasswdFailedMessage,"Failed to verify password!");
informationNote->ExecuteLD(KPasswdFailedMessage);
}
else
{

CAknInformationNote* Note = new (ELeave)CAknInformationNote;

_LIT(KPasswdMessage,"verify password!");
Note->ExecuteLD(KPasswdMessage);

}

RDecryptStream decryptedFileStream;
decryptedFileStream.AttachLC(inputFileStream, *decrypter, KNullDesC8);
CleanupClosePushL(decryptedFileStream);
HBufC* decryptedData = HBufC::NewL(decryptedFileStream, KAknExQueryTextBufLength);

CleanupStack::PopAndDestroy(decryptedData);
CleanupStack::PopAndDestroy(); // Close decryptedFileStream
decryptedFileStream.Pop();
//
//
//CleanupStack::PopAndDestroy(securityData);
CleanupStack::PopAndDestroy(); // Close outputFileStream
//CleanupStack::PopAndDestroy(decrypter);
CleanupStack::PopAndDestroy(); // Close file
CleanupStack::PopAndDestroy(); // Close fileSession;


}

Iam sending some of thje main code. please correct it and reply me.

Thu, 2007-11-22 11:28
Joined: 2004-09-14
Forum posts: 140
Re: Encryption and decryption of a password

You can see the sample I wrote on the Nokia wiki (http://wiki.forum.nokia.com/index.php/Password_based_encryption)


Paul Todd

  • Login to reply to this topic.