Не получается добавить сертификат из системного хранилища в сериализованное. Код работает без ошибок, но ничего не добавляется. В чем может быть порблема? Код приведен ниже...
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 &quStoreElement(
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.
{
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;
}
//-------------------------------------e 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
))
------------------------------
// собственно добавляем сериализованный сенртификат в хранилище 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;
}