Creating a Key
The process of creating a key in CADP for C PKCS#11 starts with creating a PKCS#11 instance. Thereafter, the following steps are programmatically executed:
- A PKCS#11 session is created. 
- A new PKCS#11 session is activated. 
- A key object is created with the required attributes within CADP for C PKCS#11. 
Note
In this document, CADP for C PKCS#11 is also referred to as CADP PKCS#11.
Each of the functions described in this section are provided in the pkcs11_sample_helper.c file. This file contains the shared functions that are used within the available CADP PKCS#11 samples provided within the GitHub site: CipherTrust Application Protection GitHub site.
Also, the APIs described in this section are included in the CADP PKCS#11 library.
To create a key in CADP PKCS#11:
- Initialize the CADP PKCS#11 library. - rc = initPKCS11Library(Path to PKCS#11 library); //from pkcs11_sample_helper.c- The - initPKCS11Libraryfunction loads the DLL and then obtains the function list from the DLL. This function uses the- C_InitializeAPI to initialize the CADP PKCS#11 library.
- Initialize the slot list. - rc = initSlotList(); //from pkcs11_sample_helper.c- The - initSlotListfunction obtains a list of the available slots within the CipherTrust Manager. This function uses- C_GetSlotListand- C_GetMechanismListAPIs.
- Open a session within the CipherTrust Manager and login as a user. - rc = openSessionAndLogin(pin, slotId); // from pkcs11_sample_helper.c- The - openSessionAndLoginfunction opens a session within the CipherTrust Manager and then logs in the session as a user. This function uses the- C_OpenSessionand- C_LoginAPIs.- For more information on PIN, refer Opening a Session section. 
- Create a key in CADP PKCS#11: - a. For a version key: - rc = createKey(keyLabel, keyAlias, genAction, lifespan, key_size); //from pkcs11_sample_helper.c- The - createKeyfunction creates a template for the key from the parameters provided and then generates the key. This function uses the- C_GenerateKeyAPI.- b. For a non-version key: - rc = createKeyS(keyLabel, key_size); // from pkcs11_sample_helper.c- The - createKeySfunction creates a template for the key from the parameters provided and then generates the key. This function uses the- C_GenerateKeyAPI.
For more information about the APIs mentioned in this section, refer to the CADP for C PKCS#11 API Guide.