This section describes how to import a key from a file using the keystore.
An externally generated key can be stored in the keystore using the import functionality. Use the CUnifiedKeyStore::ImportKey() function to import a key into the keystore.
The following steps explain the process of importing keys:
The required key is imported into the selected keystore.
The following code snippet shows how to create a file system session object, initialize keystore and member functions, and import a key.
//Create a file system session object RFs iFs; CleanupClosePushL(&iFs); //Initialise the keystore and member functions CUnifiedKeyStore* keyStore = CUnifiedKeyStore::NewL(iFs); keyStore->Initialize(iStatus); //iStatus is a TRequestStatus object ... HBufC8* keyData = NULL; CleanupStack::PushL(keyData); // Specify the path of the file containing the key details TDriveUnit sysDrive (RFs::GetSystemDrive()); TFileName keyDataFile (sysDrive.Name()); keyDataFile.Append(_LIT("<path where key is located; relative to the system drive in this case.>")); //Specify the filename TFileName buf; buf.FillZ(); buf.Copy(aDes); //Filename keyDataFile.Append(buf); //Open the file in read-only mode RFile file; User::LeaveIfError(file.Open(iFs, keyDataFile, EFileRead)); CleanupClosePushL(file); TInt fileSize = 0; User::LeaveIfError(file.Size(fileSize)); HBufC8* iKeyData; if (fileSize > 0) { iKeyData = HBufC8::NewMaxLC(fileSize); TPtr8 data(iKeyData->Des()); data.FillZ(); User::LeaveIfError(file.Read(data, fileSize)); } //Import the key into the keystore keyStore->ImportKey(0, iKeyData->Des(), usage, KLabel, accessType, TTime(0), keyInfo, iStatus); //Clean up CleanupStack::Pop(keyData); CleanupStack::PopAndDestroy(); // file CleanupStack::PopAndDestroy(); // iFs
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.