| ||||
| ||||
Не получается добавить сертификат из системного хранилища в сериализованное. Код работает без ошибок, но ничего не добавляется. В чем может быть порблема? Код приведен ниже... HCERTSTORE hSystemStore; HCERTSTORE hFileStore; PCCERT_CONTEXT pCertContext = NULL; char pszNameString[256]; BYTE* pbElement; DWORD cbElement; //------------------------------------------------------------------- // Открываем системное хранилище. if(hSystemStore = CertOpenSystemStore( 0, "MY")) { MessageDlg("System Store open " , mtInformation, TMsgDlgButtons() << mbOK, 0); } else { MessageDlg("System Store open " , mtError, TMsgDlgButtons() << mbOK, 0); return; } //------------------------------------------------------------------- //открываем второе хранилище с серилизованными сертификатами *.sst if(hFileStore = CertOpenStore( CERT_STORE_PROV_FILENAME, MY_ENCODING_TYPE, NULL, 0, L"certstore.sst")) { MessageDlg("File Store open " , mtInformation, TMsgDlgButtons() << mbOK, 0); } else { MessageDlg("File Store open " , mtError, TMsgDlgButtons() << mbOK, 0); return; } //------------------------------------------------------------------- // получаем контекст первого сертификата из системного хранилища if(pCertContext=CertEnumCertificatesInStore( hSystemStore, pCertContext)) { MessageDlg("cert available " , mtInformation, TMsgDlgButtons() << mbOK, 0); } else { MessageDlg("No certificate available " , mtError, TMsgDlgButtons() << mbOK, 0); return; } //------------------------------------------------------------------- // находим необходимую длину буфера под сер. сертификат if(CertSerializeCertificateStoreElement( pCertContext, // The existing certificate. 0, // Accept default for dwFlags, NULL, // NULL for the first function call. &cbElement)) // Address where the length of the // serialized element will be placed. { } else { MessageDlg("Finding lenght serialized " , mtError, TMsgDlgButtons() << mbOK, 0); return; } //------------------------------------------------------------------- // выделяем память if(pbElement = (BYTE*)malloc(cbElement)) { MessageDlg("memory allocated" , mtInformation, TMsgDlgButtons() << mbOK, 0); } else { MessageDlg("allocate memory " , mtError, TMsgDlgButtons() << mbOK, 0); return; } //------------------------------------------------------------------- // создаем сериализованный элемент из контекста if(CertSerializeCertificateStoreElement( pCertContext, // The certificate context source for the // serialized element. 0, // dwFlags. Accept the default. pbElement, // A pointer to where the new element will // be stored. &cbElement)) // The length of the serialized element, { MessageDlg("cert has been serialized " , mtInformation, TMsgDlgButtons() << mbOK, 0); } else { MessageDlg("cert could not be serialized " , mtError, TMsgDlgButtons() << mbOK, 0); return; } //------------------------------------------------------------------- // собственно добавляем сериализованный сенртификат в хранилище sst if(CertAddSerializedElementToStore( hFileStore, // Store where certificate is to be added. pbElement, // The serialized element for another // certificate. cbElement, // The length of pbElement. CERT_STORE_ADD_REPLACE_EXISTING, // Flag to indicate what to do if a matching // certificate is already in the store. 0, // dwFlags. Accept the default. CERT_STORE_ALL_CONTEXT_FLAG, NULL, NULL )) { MessageDlg("cert added to 2d store " , mtInformation, TMsgDlgButtons() << mbOK, 0); } else { MessageDlg("cert is not added to 2d store " , mtError, TMsgDlgButtons() << mbOK, 0); return; } //------------------------------------------------------------------- // Free memory. free(pbElement); CertCloseStore(hSystemStore,0); CertCloseStore(hFileStore,0); | ||||
Ответы: | ||||
| ||||
Hello! Good Site! Thanks you! omephbxqbfeol | ||||