cryptoki C_GenerateRandom fails

84 Views Asked by At

moved to v2 of cryptoki (CK_VERSION 204. File is 4.4.0.0). This code worked before but now doesn't:

// key is BYTE[32]
RV rv;
CK_FLAGS flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
CK_SESION_HANDLE handle;
rv = C_OpenSession(slot_id, flags, (void*)"MyApp", 0, &handle); // This succeeds
int keyLen = 32;
rv = C_GenerateRandom(handle, key, keyLen); // fails here. rv = 0x8000001A

Of course C_Initialize was called beforehand. Should this code change?

1

There are 1 best solutions below

0
On BEST ANSWER

Need to login before GenerateRandom:

rv = C_Login(handle, CKU_USER, password, passwordLen);