--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Symbian3/SDK/Source/GUID-1AA392CB-F638-5D35-993E-4A26D67A7C98.dita Fri Jun 11 12:39:03 2010 +0100
@@ -0,0 +1,147 @@
+<?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" xml:lang="en"><title>How
+to retrieve characteristics</title><prolog><metadata><keywords/></metadata></prolog><conbody>
+<p>The following example demonstrates the use of the legacy selector to retrieve
+the characteristics of an asymmetric cipher object. In the example, an implementation
+object is constructed (making use of an RSA Key Pair also generated by the
+framework) and returned. The plug-in characteristics and extended characteristics
+associated with the object are then accessed. </p>
+<codeblock id="GUID-CF2DF77C-90BD-56A0-A27D-89C4DA18EDCD" 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 value
+const TInt KKeyExponent = 65537;
+
+using namespace CryptoSpi;
+
+// Create a new CCryptoParams instance to contain the RSA Key Pair initialization data
+CCryptoParams* keyParams = CCryptoParams::NewLC();
+
+// Create an RSA Key Pair and Key Pair Generator object pointers
+CKeyPair* keyPair = NULL;
+CKeyPairGenerator * keypairImpl = NULL;
+
+// Set the RSA Key Pair Generator initialization parameters reate an RSA key pair
+keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
+keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
+
+// Retrieve an instance of an RSA Key Pair Generator implementation from the framework
+CKeyPairGeneratorFactory::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 implementation
+TRAPD(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 it
+if (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 stack
+CleanupStack::PopAndDestroy(3,keyParams);
+
+</codeblock>
+</conbody></concept>
\ No newline at end of file