opensc-pkcs11没有得到任何令牌

时间:2014-04-02 14:14:50

标签: pkcs#11 opensc

我正在使用redhat linux中的opensc-pkcs11.so编写一个示例程序。这适用于AES加密/解密的纯软件实现。我没有使用任何卡。 我的程序成功地使用cryptoki但是给出了CKR_TOKEN_NOT_PRESENT错误。 给出了代码段。

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);
    }

有人可以了解发生了什么吗?我相信opensc-pkcs11也可以用于软件实现。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

OpenSC附带的PKCS#11库仅作为驱动程序&#34;对于一堆普遍可用的cryptographic smart cards,所以除非你的计算机连接了一个物理读卡器,否则它找不到任何插槽。如果您正在寻找纯软件PKCS#11实现,那么我相信您应该从my answer to your previous question中选择一个。如果它们都不符合您的需要,那么您可以使用某些通用加密库,例如OpenSSLGnuTLSBotan