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;
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);
//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;
Forum posts: 981
What exactly do you mean? Do you want to encrypt a string? Or?
pirosl
Forum posts: 36
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
Forum posts: 981
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
Forum posts: 36
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.
Forum posts: 140
You can see the sample I wrote on the Nokia wiki (http://wiki.forum.nokia.com/index.php/Password_based_encryption)
Paul Todd