Реализовал стандартный пример из SDK, но подписать сообщение не могу. Функция CadesSignMessage вылетает с ошибкой 0х5; Необходима простая подпись. Помогите разобраться в чём может быть проблема?
Собирал в CodeGear XE.
В VS этот же код выдаёт ошибку 0х0.
Помимо ЭЦП SDK установлен еще Крипто ПРО CSP. Сертификат создал свой собственный. В КриптоАРМ им подписать данные получается.
Memo1->Clear();
HCERTSTORE hStore = NULL; // Дескритор хранилища сертификатов
//------------------------------------------------------------------------------
// Открытие хранилища сертификатов "MY" текущего пользователя.
hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0,
CERT_STORE_OPEN_EXISTING_FLAG |CERT_STORE_READONLY_FLAG |
CERT_SYSTEM_STORE_CURRENT_USER, L"MY");
if(!hStore)
{
Memo1->Lines->Add("The store could not be opened!\n");
}
else
{
Memo1->Lines->Add("The store is open!\n");
}
UnicodeString userName = "Демиденко";
//-----------------------------------------------------------------
// Получение сертификата с заданным именем из хранилища сертификатов.
PCCERT_CONTEXT pContext = NULL ; // Контекст сертификата
pContext = CertFindCertificateInStore(hStore,
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_SUBJECT_STR,
userName.c_str(), NULL);
if(pContext == NULL)
{
Memo1->Lines->Add("There is no such a certificate in the store\n");
}
else
{
Memo1->Lines->Add("Certificate init\n");
}
CRYPT_SIGN_MESSAGE_PARA signPara = { sizeof(signPara) };
signPara.dwMsgEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
signPara.pSigningCert = pContext; // 0 for window
signPara.HashAlgorithm.pszObjId = szOID_CP_GOST_R3411; //szOID_OIWSEC_sha1;
CADES_SIGN_MESSAGE_PARA para = {sizeof(para)} ;
para.pSignMessagePara = &signPara;
BYTE data[1024] ={"My Message"};
//memset(data,0,1024);
const BYTE *pbToBeSigned = &data[0] ;
DWORD cbToBeSigned[] = {sizeof(data)} ;
PCRYPT_DATA_BLOB pSignedMessage = 0;
if(!CadesSignMessage(¶,FALSE,1, &pbToBeSigned,cbToBeSigned,
&pSignedMessage))
{
Memo1->Lines->Add( "CadesSignMessage() failed");
DWORD err = GetLastError();
Memo1->Lines->Add(err);
return ;
}
if(!CadesFreeBlob(pSignedMessage))
{
Memo1->Lines->Add( "CadesFreeBlob() failed");
return;
}
Вот лог
[3352] .\Externs.cpp(33) : /Init/
[3352] .\CPSettings.cpp(193) : /Init/
[3352] cades.dll: {6020} /CCadesApp::InitInstance/ CadesApp.cpp(16) : hInstance=6E000000
[3352] cades.dll: {6020} /CadesSignMessage/ cades.cpp(2077) : (pSignPara=0x002AEB74, fDetachedSignature=0, cToBeSigned=1, rgpbToBeSigned=0x002AEB94, rgcbToBeSigned=0x002AEB98, ppSignedBlob=0x002AEB9C)
[3352] cades.dll: {6020} /CadesSignMessageImpl/ cades.cpp(1959) : Signer updating start
[3352] cades.dll: {6020} /CadesSignMessageImpl/ cades.cpp(1962) : Hash algorithm deduced
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImplNamespace::AttributeExists/ cades.cpp(183) : (pAttr=0)
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImplNamespace::UpdateSignedAttributes/ cades.cpp(379) : Signer does not have any of signing-certificate attributes
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImplNamespace::UpdateSignedAttributes/ cades.cpp(385) : Attributes copied
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImplNamespace::UpdateSignedAttributes/ cades.cpp(388) : signing-certificate(-v2) attribute assembled
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImplNamespace::UpdateSignedAttributes/ cades.cpp(391) : Signer is updated successfully
[3352] cades.dll: {6020} /CadesMsgOpenToEncode/ cades.cpp(493) : (dwMsgEncodingType=0x00010001, dwFlags=0x00000000, pvMsgEncodeInfo=0x002AE574, pszInnerContentObjID=0, pStreamInfo=0x00000000)
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImpl/ cades.cpp(441) : Start
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImpl/ cades.cpp(445) : Input parameters checked
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImpl/ cades.cpp(454) : Copy of input structures is ready
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImpl/ cades.cpp(460) : Signers updating start
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImpl/ cades.cpp(465) : Signer #0
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImplNamespace::CheckAlgorithms/ cades.cpp(409) : Public key info is exported successfully
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImplNamespace::CheckAlgorithms/ cades.cpp(416) : Signature algoritm OID info is found: 1.2.840.113549.1.1.5
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImpl/ cades.cpp(472) : Certificates equality checked
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImplNamespace::DeduceHashAlgorithm/ cades.cpp(159) : (szHashAlgorithm=1.3.14.3.2.26)
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImpl/ cades.cpp(474) : Hash algorithm deduced
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImplNamespace::AttributeExists/ cades.cpp(178) : (pAttr->pszObjId=1.2.840.113549.1.9.16.2.12)
[3352] cades.dll: {6020} /CadesMsgOpenToEncodeImpl/ cades.cpp(481) : Calling CryptMsgOpenToEncode()
[3352] cades.dll: {6020} /CadesMsgOpenToEncode/ cades.cpp(524) : (hMsg=0x00709AC0, GetLastError=0x0000000d)
[3352] cpcspi: Thread: file:line function text xcode(dcode) level: 0
[3352] cpcsp: Thread: file:line text level: 0
[3352] cpui: Thread: file:line function text xcode(dcode) level: 0
[3352] cades.dll: {6020} /CadesMsgEnhanceSignature/ cades.cpp(1150) : (hCryptMsg=0x00709AC0, dwSignatureIndex=0, pCadesSignPara=0x002AE58C)
[3352] cades.dll: {6020} /CadesMsgEnhanceSignatureImpl/ cades.cpp(1005) : Input parameters checked
[3352] cades.dll: {6020} /CadesMsgEnhanceSignatureImpl/ cades.cpp(1009) : Signer certificate ID found
[3352] cades.dll: {6020} /CadesMsgEnhanceSignatureImpl/ cades.cpp(1024) : pSignerCert=0x0074E3A8
[3352] cades.dll: {6020} /CadesMsgGetType/ CadesMsgGetType.cpp(135) : (hCryptMsg=0x00709AC0, dwSignatureIndex=0, pdwCadesType=0x002ADE54)
[3352] cades.dll: {6020} /CadesMsgGetType/ CadesMsgGetType.cpp(160) : (res=1, GetLastError=0x00000000
[3352] cades.dll: {6020} /CadesMsgEnhanceSignatureImpl/ cades.cpp(1066) : Hash algorithm deduced
[3352] cades.dll: {6020} /CadesMsgEnhanceSignatureImplNamespace::ExtractSignature/ cades.cpp(554) : Signature extracted via CMSG_ENCRYPTED_DIGEST
[3352] .\Externs.cpp(33) : /Init/
[3352] .\CPSettings.cpp(193) : /Init/
[3352] cades.dll: {6020} /CadesMsgEnhanceSignature/ cades.cpp(1160) : CAtlException, m_hr=0xc2100121
[3352] cades.dll: {6020} /CadesMsgEnhanceSignature/ cades.cpp(1179) : (res=0, GetLastError=0xc2100121
[3352] cades.dll: {6020} /CadesSignMessageImpl/ cades.cpp(2050) : Expression FAILED: ::CadesMsgEnhanceSignature(msgDecode.GetHandle(), 0, &cadesSignPara)
[3352] cades.dll: {6020} /CadesSignMessageImpl/ cades.cpp(2050) : Last win32 error thrown as exception
[3352] cades.dll: {6020} /CadesSignMessage/ cades.cpp(2097) : COleException, m_sc=0xc2100121
[3352] cades.dll: {6020} /CadesSignMessage/ cades.cpp(2109) : (res=0, GetLastError=0xc2100121
Отредактировано пользователем 27 сентября 2012 г. 19:32:28(UTC)
| Причина: Не указана