#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>
int main(int argc,char *argv[])
{
CK_OBJECT_CLASS keyClass = 0;
CK_KEY_TYPE getKeyType = 0;
CK_ULONG ulSlotCount = 0;
CK_ULONG keyLength = 0;
CK_ULONG materialLength = 0;
CK_ULONG i = 0;
int match = 0;
if (
CKR_OK != (rv = C_Initialize( &initArgs ))) {
printf( "PKCS11 example4: failed C_Initialize (error:%lx)", rv );
return -1;
}
{
printf( "PKCS11 example4: memory allocation failed" );
return -2;
}
if (
CKR_OK == (rv = C_GetSlotList(
CK_FALSE, pSlotList, &ulSlotCount )))
{
for( i=0; i < ulSlotCount; i++ )
{
{
match = strncmp( (const char*)oneSlot.slotDescription, "KMIP SLOT1 ", 64 );
if (0 == match)
{
if (
CKR_OK != (rv = C_OpenSession( pSlotList[i], flags, NULL, NULL, &hSession ))) {
printf( "PKCS11 example4: slot %ld failed to open a session (error:%lx)", pSlotList[i], rv );
break;
}
{
keyLength = 16;
materialLength = sizeof(keyMaterial);
strncpy( (char*)label, "AES key Generated by the token", 30 );
keyTemplate[0].
pValue = &bTFlag;
keyTemplate[1].
pValue = label;
keyTemplate[2].
pValue = &keyLength;
keyTemplate[3].
pValue = &bTFlag;
keyTemplate[4].
pValue = &bTFlag;
{
printf( "PKCS11 example4: slot %ld failed to generate key on token (error:%lx)", pSlotList[i], rv );
}
else
{
getTemplate[0].
pValue = &keyClass;
getTemplate[1].
pValue = label2;
getTemplate[2].
pValue = keyMaterial;
getTemplate[3].
pValue = &bUsage;
getTemplate[4].
pValue = &getKeyType;
{
printf( "PKCS11 example4: slot %ld failed to get key attributes (error:%lx)", pSlotList[i], rv );
}
else
{
;
}
}
if (
CKR_OK != (rv = C_Logout( hSession ))) {
printf( "PKCS11 example4: slot %ld failed to logout of token (error:%lx)", pSlotList[i], rv );
}
}
if (
CKR_OK != (rv = C_CloseSession( hSession ))) {
printf( "PKCS11 example4: slot %ld failed to close an active token session (error:%lx)", pSlotList[i], rv );
break;
}
}
}
}
}
}
if (
NULL_PTR != pSlotList) free( pSlotList );
printf( "PKCS11 example4: failed C_Finalize %lx", rv );
return -3;
}
return 0;
}