Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --><!-- This component and the accompanying materials are made available under the terms of the License "Eclipse Public License v1.0" which accompanies this distribution, and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --><!-- Initial Contributors: Nokia Corporation - initial contribution.Contributors: --><!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"><concept id="GUID-1AA392CB-F638-5D35-993E-4A26D67A7C98-GENID-1-12-1-26-1-1-11-1-1-3-1-4-1-5-1" xml:lang="en"><title>Howto retrieve characteristics</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>The following example demonstrates the use of the legacy selector to retrievethe characteristics of an asymmetric cipher object. In the example, an implementationobject is constructed (making use of an RSA Key Pair also generated by theframework) and returned. The plug-in characteristics and extended characteristicsassociated with the object are then accessed. </p><codeblock id="GUID-CF2DF77C-90BD-56A0-A27D-89C4DA18EDCD-GENID-1-12-1-26-1-1-11-1-1-3-1-4-1-5-1-2-2" xml:space="preserve">#include <cryptoasymmetriccipherapi.h>#include <cryptokeypairgeneratorapi.h>#include <cryptospidef.h>#include <plugincharacteristics.h>#include <extendedcharacteristics.h>#include <keypair.h>// Constant definition for the RSA key pair generator exponent valueconst TInt KKeyExponent = 65537;using namespace CryptoSpi;// Create a new CCryptoParams instance to contain the RSA Key Pair initialization dataCCryptoParams* keyParams = CCryptoParams::NewLC(); // Create an RSA Key Pair and Key Pair Generator object pointersCKeyPair* keyPair = NULL;CKeyPairGenerator * keypairImpl = NULL; // Set the RSA Key Pair Generator initialization parameters reate an RSA key pairkeyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);// Retrieve an instance of an RSA Key Pair Generator implementation from the frameworkCKeyPairGeneratorFactory::CreateKeyPairGeneratorL( keypairImpl, KRSAKeyPairGeneratorUid, keyParams);CleanupStack::PushL(keypairImpl);// Create an RSA Key Pair keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair);CleanupStack::PushL(keyPair);// Create and initialize a pointer for the asymmetric cipher implementation object CAsymmetricCipher* asymmetricCipherImpl = NULL;// If successful, the 'CreateAsymmetricCipherL' method returns KErrNone and sets the // asymmetricCipherImpl pointer to point to the constructed implementationTRAPD(err, CAsymmetricCipherFactory::CreateAsymmetricCipherL(asymmetricCipherImpl, KRsaCipherUid, keyPair->PrivateKey(), KCryptoModeEncryptUid, KPaddingModeNoneUid, NULL));// Having successfully constructed the asymmetric cipher implementation object, // it is possible to retrieve the plug-in characteristics associated with itif (asymmetricCipherImpl && (err == KErrNone)) { CleanupStack::PushL(asymmetricCipherImpl); // Retrieving common and algorithm-specific characteristics // Create a constant pointer of type TCharacteristics used to access the // asymmetric cipher plug-in's common and algorithm-specific characteristics const TCharacteristics* chars(NULL); // Retrieve the common and algorithm-specific characteristics by calling the // 'GetCharacteristicsL' method passing in TCharacteristics pointer asymmetricCipherImpl->GetCharacteristicsL(chars); // Static cast the characteristics to type TAsymmetricCipherCharacteristics const TAsymmetricCipherCharacteristics* asymmetricChars = static_cast<const TAsymmetricCipherCharacteristics*>(chars); // Retrieve the common characteristics from the TASymmetricCipherCharacteristics // object const TCommonCharacteristics* asymmetricCommonChars = &asymmetricChars->cmn; TUid implementationId; TBool hardwareSupported; TRomLitC16 creatorName; TInt maximumKeyLength; TInt32 supportedPaddingModes; // Example of extracting asymmetric common characteristics implementationId.iUid = asymmetricCommonChars->iImplementationUID; hardwareSupported = asymmetricCommonChars->iIsHardwareSupported; creatorName = *(asymmetricCommonChars->iCreatorName); // Example of extracting asymmetric algorithm specific characteristics maximumKeyLength = asymmetricChars->iMaximumKeyLength; supportedPaddingModes = *(asymmetricChars->iSupportedPaddingModes); //Retrieving extended characteristics // Create a constant pointer of type CExtendedCharacteristics used to store and // access the asymmetric cipher plug-in extended characteristics. Retrieve // the data by calling the 'GetExtendedCharacteristicsL' method and store the // returned pointer const CExtendedCharacteristics* extendedChars = asymmetricCipherImpl->GetExtendedCharacteristicsL(); // Const casting the pointer to the CExtendedCharacteristics object allows it to // be pushed onto the cleanup stack CExtendedCharacteristics* ncExtendedChars = const_cast<CExtendedCharacteristics*>(extendedChars); CleanupStack::PushL(ncExtendedChars); TInt concurrency; // Each of the extended characteristics for the particular cryptographic // implementation can then be accessed by passing the UID value into the // appropriate 'Get' method concurrency = extendedChars->GetTIntCharacteristicL(KConcurrencyTypeUid); // Alternatively, extended characteristic retrieval can be achieved via the // ListExtendedCharacteristics() method of the CExtendedCharacteristics Object. // Using the 'ListExtendedCharacteristics' function returns a pointer to a // CCryptoParams object, that contains a list of all associated extended // characteristics const CCryptoParams* extendedCryptoParams = extendedChars->ListExtendedCharacteristics(); TBool exclusiveUse; // The extended characteristics can then be accessed in much the same way as // before, making a call to the appropriate 'Get' method with the UID value of the // required type exclusiveUse = extendedCryptoParams->GetTIntL(KExclusiveUseTypeUid); CleanupStack::PopAndDestroy(2, asymmetricCipherImpl); }// Pop and destroy the remaining items on the cleanup stackCleanupStack::PopAndDestroy(3,keyParams);</codeblock></conbody></concept>