| ||||
| ||||
Пытаюсь подписать сообщение но функция CryptMsgCalculateEncodedLength возвращает ноль, если параметр HashAlgorithm.pszObjId равен szOID_CP_GOST_R3411_R3410, но если он равен szOID_RSA_MD то все отрабатывает нормально? В чем может быть дело? Вот исходник: const BYTE* pbContent = (BYTE*)"Test Message."; DWORD cbContent; // Size of message HCRYPTPROV hCryptProv; // CSP handle HCERTSTORE hStoreHandle; // Store handle PCCERT_CONTEXT pSignerCert; // Signer certificate CMSG_SIGNER_ENCODE_INFO SignerEncodeInfo; CMSG_SIGNER_ENCODE_INFO SignerEncodeInfoArray[1]; CERT_BLOB SignerCertBlob; CERT_BLOB SignerCertBlobArray[1]; CMSG_SIGNED_ENCODE_INFO SignedMsgEncodeInfo; DWORD cbEncodedBlob; BYTE* pbEncodedBlob; HCRYPTMSG hMsg; DWORD dwKeySpec; CRYPT_VERIFY_MESSAGE_PARA msgPara; //äëèííà ïîäïèñûâàåìîãî ñîîáùåíèÿ cbContent = strlen((char *) pbContent)+1; //îòêðûâàåì õðàíèëèùå MY hStoreHandle = CertOpenStore( CERT_STORE_PROV_SYSTEM, 0, NULL, CERT_SYSTEM_STORE_CURRENT_USER, L"MY"); if(!hStoreHandle) { MyHandleError( "Could not open the MY system store."); } //ïîëó÷àåì êîíòåêñò ñåðòèôèêàòà êîòîðûì áóäåì ïîäïèñûâàòü pSignerCert = CertFindCertificateInStore( hStoreHandle, MY_ENCODING_TYPE, 0, CERT_FIND_SUBJECT_STR, SIGNER_NAME, NULL); if (!pSignerCert) { MyHandleError("Cert not found.\n"); } //ïîëó÷åíèå äåñêðèïòîðà çàêðûòîãî êëþ÷à if(!(CryptAcquireCertificatePrivateKey( pSignerCert, 0, NULL, &hCryptProv, &dwKeySpec, NULL))) { MyHandleError("CryptAcquireContext failed"); } memset(&SignerEncodeInfo, 0, sizeof(CMSG_SIGNER_ENCODE_INFO)); SignerEncodeInfo.cbSize = sizeof(CMSG_SIGNER_ENCODE_INFO); SignerEncodeInfo.pCertInfo = pSignerCert->pCertInfo; SignerEncodeInfo.hCryptProv = hCryptProv; SignerEncodeInfo.dwKeySpec = dwKeySpec; SignerEncodeInfo.HashAlgorithm.pszObjId = szOID_RSA_MD5; SignerEncodeInfo.pvHashAuxInfo = NULL; SignerEncodeInfoArray[0] = SignerEncodeInfo; SignerCertBlob.cbData = pSignerCert->cbCertEncoded; SignerCertBlob.pbData = pSignerCert->pbCertEncoded; SignerCertBlobArray[0] = SignerCertBlob; memset(&SignedMsgEncodeInfo, 0, sizeof(CMSG_SIGNED_ENCODE_INFO)); SignedMsgEncodeInfo.cbSize = sizeof(CMSG_SIGNED_ENCODE_INFO); SignedMsgEncodeInfo.cSigners = 1; SignedMsgEncodeInfo.rgSigners = SignerEncodeInfoArray; SignedMsgEncodeInfo.cCertEncoded = 1; SignedMsgEncodeInfo.rgCertEncoded = SignerCertBlobArray; if(!(cbEncodedBlob = CryptMsgCalculateEncodedLength( MY_ENCODING_TYPE, // Message encoding type 0, // Flags CMSG_SIGNED, // Message type &SignedMsgEncodeInfo, // Pointer to structure NULL, // Inner content OID cbContent))) // Size of content { MyHandleError("Getting cbEncodedBlob length failed."); } | ||||
Ответы: | ||||
| ||||
Ключ гостовый? Если да, то алгоритм хэша это szOID_CP_GOST_R3411, а szOID_CP_GOST_R3411_R3410 - это алгоритм подписи по 94 госту. | ||||