0

I am writing a sample program using opensc-pkcs11.so in redhat linux. This is for pure software implementation of AES encryption/decryption. I am not using for any card. My program intilizes the cryptoki successfully but giving CKR_TOKEN_NOT_PRESENT error. code snippet is given.

CK_FUNCTION_LIST_PTR pFunctionList; 
CK_C_Initialize pC_Initialize; 
CK_RV rv; 

rv = C_GetFunctionList(&pFunctionList); 
if(rv == CKR_OK)
pC_Initialize = pFunctionList -> C_Initialize; 

rv = (*pC_Initialize)(NULL_PTR);

    CK_ULONG ulSlotCount;
    CK_SLOT_ID_PTR pSlotList;

    CK_C_GetSlotList pC_GetSlotList;
    pC_GetSlotList = pFunctionList -> C_GetSlotList; 
    rv = (*pC_GetSlotList)(CK_FALSE, NULL_PTR, &ulSlotCount);

    /* Get list of all slots */
    //rv = C_GetSlotList(FALSE, NULL_PTR, &ulSlotCount);

    if (rv == CKR_OK) 
    {
        cout<<"ulSlotCount="<<ulSlotCount<<endl;
        pSlotList =
        (CK_SLOT_ID_PTR)
        malloc(ulSlotCount*sizeof(CK_SLOT_ID));
        //rv = C_GetSlotList(FALSE, pSlotList, &ulSlotCount);
        rv = (*pC_GetSlotList)(CK_FALSE, pSlotList, &ulSlotCount);
        if (rv == CKR_OK) 
        {
        /* Now use that list of all slots */
            l_lSlotId = pSlotList[0];
        cerr<<"lSlotId="<<l_lSlotId<<endl;


        }

        CK_SLOT_INFO slotInfo;
        CK_TOKEN_INFO tokenInfo;
        CK_C_GetSlotInfo pC_GetSlotInfo;
        pC_GetSlotInfo = pFunctionList -> C_GetSlotInfo;

        /* Get slot information for first slot */
        rv = (*pC_GetSlotInfo)(pSlotList[0], &slotInfo);
        fprintf(stderr, "pC_GetSlotInfo: rv = 0x%.8X\n", rv);
        if(rv == CKR_OK)
                   {
        /* Get token information for first slot */
            cerr<<"pC_GetSlotInfo OK"<<endl;

            CK_C_GetTokenInfo pC_GetTokenInfo;
            pC_GetTokenInfo = pFunctionList -> C_GetTokenInfo;
            rv = (*pC_GetTokenInfo)(pSlotList[0], &tokenInfo);
        }
        fprintf(stderr, "pC_GetTokenInfo: rv = 0x%.8X\n", rv);
        if (rv == CKR_TOKEN_NOT_PRESENT) 
        {
            cerr<<"CKR_TOKEN_NOT_PRESENT"<<endl;
        }

        free(pSlotList);
    }

Can anybody give idea about what is happening? I believe opensc-pkcs11 can be used for just software implementation also. Thanks in advance.

4

1 回答 1

0

OpenSC 附带的 PKCS#11 库“仅作为驱动程序”用于一堆普遍可用的加密智能卡,因此除非您将物理读卡器连接到您的计算机,否则它不会找到任何插槽。如果您正在寻找纯软件 PKCS#11 实现,那么我相信您应该从我对上一个问题的回答中选择一个。如果它们都不适合您的需要,那么也许您可以使用一些通用加密库,例如OpenSSLGnuTLSBotan

于 2014-04-02T18:43:56.973 回答