我有一個PKCS11令牌和一個由應用程序創建的對象。我試圖編寫另一個讀取對象的應用程序。我設法使用C_FindObjectsInit()和C_FindObjects()來查找對象。然後我調用C_GetObjectSize()來確保對象的大小與預期的一樣。它是。接下來,我調用C_GetAttributeValue()來讀取對象。返回的模板具有正確的ulValueLen,但pValue爲0.我做錯了什麼?讀取對象的代碼如下:從PKCS11令牌讀取對象
CK_ATTRIBUTE dataTemplate[] = {
{CKA_VALUE, NULL_PTR, 0}
};
ret = C_GetObjectSize(hSession, hObject, &ulSize);
if(ret != CKR_OK) {
LOGE("C_GetObjectSize exception! Return value was %x", (int)ret);
return -1;
}
LOGD("Size of object is %d", ulSize);
ret = C_GetAttributeValue(hSession, hObject, dataTemplate, sizeof(dataTemplate)/sizeof(CK_ATTRIBUTE));
if(ret != CKR_OK)
{
LOGE("C_GetAttributeValue error! Return value was %d", (int)ret);
return -1;
}