I am trying to interact with HSM using PKCS#11 functions given by vendor. I use below series of function to generate secret key, encrypt and decrypt data. Below sequence works good.
C_InitializeC_OpenSessionC_LoginC_GenerateKey //3DES KEYC_EncryptInitC_EncryptC_DecryptInitC_DecryptC_LogoutC_CloseSession
My Questions:
After using C_Logout & C_CloseSession is there a way to reuse same KEY(generated earlier) again by logging back and opening session again with same login credentials?
When I use C_CreateObject does it create session object and destroy it on using C_CloseSession?
                        
Yes, just set
CKA_TOKENtoCK_TRUEand provide a label usingCKA_LABELto search for it usingC_FindObjects.Well, yes, according to the PKCS#11 specifications (v2.20, 10.4, Table 21):
Note that your token may not allow all possible attributes or attribute combinations to be set, and may have memory and other limitations.