Не могу создать файла на Рутокене
Пишется учебное приложение. Требуется: создать файл на токене с некоторым содержанием.
Запускаю приложение, проверяю наличие файла rtEditor'ом, однако файла не видно..
Исходный код приложения (фрагмент).
HMODULE lib;
CK_RV result;
CK_ULONG ulSlotCount;
CK_SLOT_ID slots[100];
CK_SESSION_HANDLE hSession;
CK_RV rv;
CK_C_Initialize pC_Initialize;
CK_C_Finalize pC_Finalize;
CK_C_GetSlotList pC_GetSlotList;
CK_C_OpenSession pC_OpenSession;
CK_C_CloseSession pC_CloseSession;
CK_C_Login pC_Login;
CK_C_Logout pC_Logout;
CK_C_GetTokenInfo pC_GetTokenInfo;
CK_C_GenerateRandom pC_GenerateRandom;
CK_C_GenerateKey pC_GenerateKey;
CK_C_CreateObject pC_CreateObject;
CK_C_DestroyObject pC_DestroyObject;
CK_C_FindObjectsInit pC_FindObjectsInit;
CK_C_FindObjects pC_FindObjects;
CK_C_FindObjectsFinal pC_FindObjectsFinal;
CK_C_EncryptInit pC_EncryptInit;
CK_C_Encrypt pC_Encrypt;
CK_C_DecryptInit pC_DecryptInit;
CK_C_Decrypt pC_Decrypt;
CK_C_GetSessionInfo pC_GetSessionInfo;
lib = LoadLibrary("rtpkcs11.dll");
pC_Initialize = (CK_C_Initialize)GetProcAddress(lib, "C_Initialize");
pC_Finalize = (CK_C_Finalize)GetProcAddress(lib, "C_Finalize");
pC_GetSlotList = (CK_C_GetSlotList)GetProcAddress(lib, "C_GetSlotList");
pC_OpenSession = (CK_C_OpenSession)GetProcAddress(lib, "C_OpenSession");
pC_CloseSession = (CK_C_CloseSession)GetProcAddress(lib, "C_CloseSession");
pC_Login = (CK_C_Login)GetProcAddress(lib, "C_Login");
pC_Logout = (CK_C_Logout)GetProcAddress(lib, "C_Logout");
pC_GetTokenInfo = (CK_C_GetTokenInfo)GetProcAddress(lib, "C_GetTokenInfo");
pC_GenerateRandom = (CK_C_GenerateRandom)GetProcAddress(lib, "C_GenerateRandom");
pC_GenerateKey = (CK_C_GenerateKey)GetProcAddress(lib, "C_GenerateKey");
pC_CreateObject = (CK_C_CreateObject)GetProcAddress(lib, "C_CreateObject");
pC_DestroyObject = (CK_C_DestroyObject)GetProcAddress(lib, "C_DestroyObject");
pC_FindObjectsInit = (CK_C_FindObjectsInit)GetProcAddress(lib, "C_FindObjectsInit");
pC_FindObjects = (CK_C_FindObjects)GetProcAddress(lib, "C_FindObjects");
pC_FindObjectsFinal = (CK_C_FindObjectsFinal)GetProcAddress(lib, "C_FindObjectsFinal");
pC_EncryptInit = (CK_C_EncryptInit)GetProcAddress(lib, "C_EncryptInit");
pC_Encrypt = (CK_C_Encrypt)GetProcAddress(lib, "C_Encrypt");
pC_DecryptInit = (CK_C_DecryptInit)GetProcAddress(lib, "C_DecryptInit");
pC_Decrypt = (CK_C_Decrypt)GetProcAddress(lib, "C_Decrypt");
pC_GetSessionInfo = (CK_C_GetSessionInfo)GetProcAddress(lib, "C_GetSessionInfo");
rv=pC_Initialize(NULL);
if (rv!=CKR_OK) {
ShowMessage("Error!");
}
ulSlotCount = 100;
rv=pC_GetSlotList(TRUE, slots, &ulSlotCount);
if (rv!=CKR_OK) {
ShowMessage("Error!");
}
rv=pC_OpenSession(slots[0],(CKF_SERIAL_SESSION | CKF_RW_SESSION),0,0,&(hSession));
if (rv!=CKR_OK) {
ShowMessage("Error!");
}
rv=pC_Login(hSession,CKU_USER,"12345678",8);
if (rv!=CKR_OK) {
ShowMessage("Error!");
}
CK_OBJECT_CLASS dataClass = CKO_DATA;
CK_CHAR application[] = {"myapp1"};
CK_BYTE dataValue[] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77};
CK_CHAR label[] = {"mylabel1"};
CK_BYTE ifTrue = TRUE;
CK_BYTE ifFalse = FALSE;
CK_ATTRIBUTE dataTemplate[] = {
{CKA_CLASS, &dataClass, sizeof(dataClass)},
{CKA_TOKEN, &ifTrue, sizeof(ifTrue)},
{CKA_PRIVATE, &ifFalse, sizeof(ifFalse)},
{CKA_APPLICATION, application, sizeof(application)},
{CKA_LABEL, &label, sizeof(label)},
{CKA_VALUE, dataValue, sizeof(dataValue)}
};
CK_OBJECT_HANDLE hData;
rv=pC_CreateObject(hSession, &dataTemplate[0], 6, &hData);
if (rv!=CKR_OK) {
ShowMessage("Error!");
}
rv=pC_Logout(hSession);
if (rv!=CKR_OK) {
ShowMessage("Error!");
}
rv=pC_CloseSession(hSession);
if (rv!=CKR_OK) {
ShowMessage("Error!");
}
rv=pC_Finalize(NULL);
if (rv!=CKR_OK) {
ShowMessage("Error!");
}
FreeLibrary(lib);