本文整理汇总了C++中CHash::Hash方法的典型用法代码示例。如果您正苦于以下问题:C++ CHash::Hash方法的具体用法?C++ CHash::Hash怎么用?C++ CHash::Hash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHash
的用法示例。
在下文中一共展示了CHash::Hash方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Hash
static long Hash(tHashAlgo hashAlgo, const CByteArray & oData)
{
CHash oHash;
CByteArray oHashData = oHash.Hash(hashAlgo, oData);
printf("Hash: %s\n", oHashData.ToString(true, false).c_str());
WriteFile("", "hash.bin", oHashData);
return 0;
}
示例2: doTestStepL
TVerdict CHashIncrementalHashWithCopyStep::doTestStepL()
{
if (TestStepResult()==EPass)
{
//Assume faliure, unless all is successful
SetTestStepResult(EFail);
INFO_PRINTF1(_L("*** Hash - Incremental Hash with Copy ***"));
INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
TVariantPtrC algorithmUid;
TVariantPtrC operationModeUid;
TPtrC sourcePath;
TPtrC expectedHash;
//Extract the Test Case ID parameter from the specified INI file
if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationModeUid) ||
!GetStringFromConfig(ConfigSection(),KConfigSourcePath,sourcePath) ||
!GetStringFromConfig(ConfigSection(),KConfigExHashHmacValue,expectedHash))
{
ERR_PRINTF1(_L("** Error: Failed to Load Configuration Parameters **"));
SetTestStepResult(EFail);
}
else
{
//Create a pointer for the Hash Implementation Object
CHash* hashImpl = NULL;
//Retrieve a Hash Factory Object
TRAPD(err,CHashFactory::CreateHashL(hashImpl,
algorithmUid,
operationModeUid,
NULL,
NULL));
if(hashImpl && (err == KErrNone))
{
//Push the Hash Implementation Object onto the Cleanup Stack
CleanupStack::PushL(hashImpl);
RFs fsSession;
//Create a connection to the file server
err = fsSession.Connect();
if(err != KErrNone)
{
ERR_PRINTF2(_L("*** Error: File Server Connection - %d ***"), err);
SetTestStepResult(EFail);
}
else
{
RFile sourceFile;
CleanupClosePushL(sourceFile);
//Open the specified source file
err = sourceFile.Open(fsSession,sourcePath, EFileRead);
if(err != KErrNone)
{
ERR_PRINTF2(_L("*** Error: Opening Source File - %d ***"), err);
SetTestStepResult(EFail);
}
else
{
TInt sourceLength = 0;
TInt readPosition = 0;
TInt readIncrement = 0;
TBool hashComplete = EFalse;
TBool hashCopied = EFalse;
TPtrC8 hashStr;
CHash* hashCopyImpl = NULL;
User::LeaveIfError(sourceFile.Size(sourceLength));
//Divide the total size of the source file up into individual equal sized blocks to read
//over several increments
readIncrement = sourceLength/KDataReadBlocks;
do
{
//Create a heap based descriptor to store the data
HBufC8* sourceData = HBufC8::NewL(readIncrement);
CleanupStack::PushL(sourceData);
TPtr8 sourcePtr = sourceData->Des();
//Read in a block of data from the source file from the current position
err = sourceFile.Read(readPosition,sourcePtr,readIncrement);
//Update the read position by adding the number of bytes read
readPosition += readIncrement;
if(readPosition == readIncrement)
{
//Read in the first block from the data file into the Hash implementation object
//.........这里部分代码省略.........
示例3: doTestStepL
TVerdict CHmacSetOperationModeCheckingStep::doTestStepL()
{
if (TestStepResult()==EPass)
{
//Assume faliure, unless all is successful
SetTestStepResult(EFail);
INFO_PRINTF1(_L("*** Hmac - Set Operation Mode Checking ***"));
INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
TVariantPtrC algorithmUid;
TVariantPtrC operationModeUid;
TVariantPtrC secondOperationModeUid;
TPtrC sourcePath;
TPtrC expectedHash;
TPtrC expectedHmac;
TPtrC encryptKey;
TVariantPtrC keyType;
//Extract the Test Case ID parameter from the specified INI file
if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationModeUid) ||
!GetStringFromConfig(ConfigSection(),KConfigSecondOperationMode,secondOperationModeUid) ||
!GetStringFromConfig(ConfigSection(),KConfigSourcePath,sourcePath) ||
!GetStringFromConfig(ConfigSection(),KConfigExHashHmacValue,expectedHash) ||
!GetStringFromConfig(ConfigSection(),KConfigExSecondHashHmacValue,expectedHmac) ||
!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
{
ERR_PRINTF1(_L("** Error: Failed to Load Configuration Parameters **"));
SetTestStepResult(EFail);
}
else
{
RFs fsSession;
//Create a connection to the file server
User::LeaveIfError(fsSession.Connect());
RFile sourceFile;
CleanupClosePushL(sourceFile);
//Open the specified source file
User::LeaveIfError(sourceFile.Open(fsSession,sourcePath, EFileRead));
TInt sourceLength = 0;
User::LeaveIfError(sourceFile.Size(sourceLength));
//Create a heap based descriptor to store the data
HBufC8* sourceData = HBufC8::NewL(sourceLength);
CleanupStack::PushL(sourceData);
TPtr8 sourcePtr = sourceData->Des();
sourceFile.Read(sourcePtr);
if(sourcePtr.Length() != sourceLength)
{
ERR_PRINTF1(_L("*** Error: Reading Source File ***"));
SetTestStepResult(EFail);
}
else
{
//Create a pointer for the Hash + Key (Hmac) Implementation Object
CHash* hashHmacImpl = NULL;
//Convert encryption key to an 8 Bit Descriptor
HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
TPtr8 keyStrPtr = keyStr->Des();
keyStrPtr.Copy(encryptKey);
//Create an new CryptoParams object to encapsulate the invalid key type and key string
CCryptoParams* keyParams = CCryptoParams::NewL();
CleanupStack::PushL(keyParams);
keyParams->AddL(*keyStr,keyType);
//Create a valid CKey Object
TKeyProperty keyProperty;
CKey* key = CKey::NewL(keyProperty,*keyParams);
CleanupStack::PushL(key);
//Construct an initial hash object with NO key, Catching any possible Leaves
TRAPD(err,CHashFactory::CreateHashL(
hashHmacImpl,
algorithmUid,
operationModeUid,
NULL,
NULL));
if(hashHmacImpl && (err == KErrNone))
{
//Push the Implementation Object onto the Cleanup Stack
CleanupStack::PushL(hashHmacImpl);
//Create a NULL TCharacteristics pointer
const TCharacteristics* charsPtrA(NULL);
//.........这里部分代码省略.........