WEB开发网
开发学院手机开发Symbian 开发 Symbian 基于口令的加密(Password_Based_Encrypti... 阅读

Symbian 基于口令的加密(Password_Based_Encryption)

 2010-03-26 15:56:00 来源:WEB开发网   
核心提示:header.ExternalizeL(aStream);// and the encrypted textconst TInt length = ciphertextPtr.Length();aStream.WriteInt32L(length);aStream.WriteL(ciphertextPtr, lengt

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

Tags:Symbian 基于 口令

编辑录入:coldstar [复制链接] [打 印]
赞助商链接