Symbian 基于口令的加密(Password_Based_Encryption)
2010-03-26 15:56:00 来源:WEB开发网header.ExternalizeL(aStream);
// and the encrypted text
const TInt length = ciphertextPtr.Length();
aStream.WriteInt32L(length);
aStream.WriteL(ciphertextPtr, length);
CleanupStack::PopAndDestroy(3, element); // ciphertext, encrypter, element
}
下面是上面的逆过程
HBufC8* CExampleStubAppUi::DecryptDataL(const TDesC& aPassword, RReadStream& aStream)
{
const TPtrC8 passwordPtr(REINTERPRET_CAST(const TUint8*, aPassword.Ptr()), aPassword.Length() * sizeof(TText));
const TPBPassword encryptionKey(passwordPtr);
// Recover the encryption data from the stream
CPBEncryptionData* encryptionData = CPBEncryptionData::NewLC(aStream);
// and then read the encrypted text
const TInt length = aStream.ReadInt32L();
HBufC8* encryptedBlob = HBufC8::NewLC(length);
TPtr8 encryptedBlobPtr = encryptedBlob->Des();
aStream.ReadL(encryptedBlobPtr, length);
// now create an element with the encryption data
// and get the decryptor object based on the encryption data
CPBEncryptElement* element = CPBEncryptElement::NewLC(*encryptionData, encryptionKey);
CPBDecryptor* decrypter = element->NewDecryptLC();
// Find out how big the result will be and allocate space for it
HBufC8* plaintext = HBufC8::NewLC(decrypter->MaxFinalOutputLength(encryptedBlobPtr.Length()));
TPtr8 plaintextPtr = plaintext->Des();
// Now decrypt the data
decrypter->ProcessFinalL(encryptedBlobPtr, plaintextPtr);
CleanupStack::Pop(plaintext);
CleanupStack::PopAndDestroy(4, encryptionData); // decrypter, encryptedblob, element, encryptionData
return plaintext;
}
最后给出示范代码
http://wiki.forum.nokia.com/index.php/File:ExampleStub_PBEExample2.zip
- ››基于IP地址的vsftp服务器
- ››基于MySQL 水平分区的优化示例
- ››基于CentOS5的Linux下pptp和openvpn的搭建及配置
- ››Symbian S60 SocketConnection参数
- ››Symbian乏力:2010年诺基亚悲情大事记
- ››Symbian三大升级开启2011年新战略
- ››Symbian/Android/iOS/WM安装包对比
- ››基于JavaScript的网页版塔防游戏
- ››基于Android平台 QQ大战360手机游戏爆红
- ››Symbian一个活动对象的测试例子
- ››Symbian ListBox控件
- ››Symbian下自动切换SDK的批处理代码
更多精彩
赞助商链接