Статус: Активный участник
Группы: Участники
Зарегистрирован: 27.04.2012(UTC) Сообщений: 119 Откуда: Digital Design Сказал «Спасибо»: 19 раз Поблагодарили: 1 раз в 1 постах
|
Помогите, пожалуйста. Пытаюсь добавить в подписанное сообщение отвязанной УЭЦП ещё одну УЭЦП. Делаю всё по примеру (http://cpdn.cryptopro.ru/content/cades/samplelowlevelapiaddsign.html), но функция постоянно завершается с ошибкой, не понимаю в чём может быть проблема. Код:
- (DWORD) cosignMessage:(CRYPT_DATA_BLOB*) pSignedMessageBlob to:(CRYPT_DATA_BLOB*)pCosignedMessageBlob toFile:(const char*)outFilename{
printf("\nRunning function: cosignMessage\n");
DWORD cbCosignedMessageBlob=0;
BYTE *pbCosignedMessageBlob = NULL;
HCRYPTMSG hMsg = CryptMsgOpenToDecode(
TYPE_DER, // Encoding type.
CMSG_DETACHED_FLAG, // Flags.
0, // Use the default message type.
hCryptProv, // Cryptographic provider.
0, // Recipient information.
0); // Stream information.
if (hMsg)
printf("The message to decode is open. \n");
else{
return [self handleError:"OpenToDecode failed"];
}
if(!CryptMsgUpdate(
hMsg, // Handle to the message
pSignedMessageBlob->pbData,//signature_mem, // Pointer to the content
pSignedMessageBlob->cbData,//signature_len, // Size of the content
TRUE)){
return [self handleError:"CryptMsgUpdate() 1 failed"];
}
if (!CryptMsgUpdate(
hMsg, // Handle to the message
pCosignedMessageBlob->pbData, // Pointer to the encoded blob
pCosignedMessageBlob->cbData, // Size of the encoded blob
TRUE)){ // Last call)
return [self handleError:"CryptMsgUpdate() 2 failed"];
}
printf("The encoded blob has been added to the message. \n");
CMSG_SIGNER_ENCODE_INFO SignerEncodeInfo = {sizeof(CMSG_SIGNER_ENCODE_INFO)};
// memset(&SignerEncodeInfo, 0, sizeof(CMSG_SIGNER_ENCODE_INFO));
SignerEncodeInfo.cbSize = sizeof(CMSG_SIGNER_ENCODE_INFO);
SignerEncodeInfo.pCertInfo = pUserCert->pCertInfo;
SignerEncodeInfo.hCryptProv = hCryptProv;
SignerEncodeInfo.dwKeySpec = keytype;
SignerEncodeInfo.HashAlgorithm = HashAlgorithm;
SignerEncodeInfo.pvHashAuxInfo = NULL;
CADES_SERVICE_CONNECTION_PARA tsp;
memset(&tsp, 0, sizeof(CADES_SERVICE_CONNECTION_PARA));
tsp.dwSize = sizeof(CADES_SERVICE_CONNECTION_PARA);
tsp.wszUri = tspUrl.c_str();
CADES_SIGN_PARA enParams = {sizeof(enParams)};
// memset(&enParams, 0, sizeof(CADES_SIGN_PARA));
// enParams.dwSize = sizeof(CADES_SIGN_PARA);
// enParams.pTspConnectionPara = &tsp;
enParams.dwCadesType = CADES_X_LONG_TYPE_1;
CADES_COSIGN_PARA cosignPara = {sizeof(cosignPara)};
// memset(&cosignPara, 0, sizeof(CADES_COSIGN_PARA));
cosignPara.pSigner = &SignerEncodeInfo;
cosignPara.pCadesSignPara = &enParams;
if (!CadesMsgAddEnhancedSignature(hMsg, &cosignPara)) {
return [self handleError:"CadesMsgAddEnhancedSignature() failed"];
}
if (!CryptMsgGetParam(
hMsg, // Handle to the message
CMSG_ENCODED_MESSAGE, // Parameter type
0, // Index
0, // Address for returned info
&cbCosignedMessageBlob)){ // Size of the returned info
return [self handleError:"Decode CMSG_ENCODED_MESSAGE failed"];
}
printf("The message parameter (CMSG_ENCODED_MESSAGE) has been acquired. Message size: %d\n", cbCosignedMessageBlob);
pbCosignedMessageBlob = (BYTE *) malloc(cbCosignedMessageBlob);
if (!pbCosignedMessageBlob){
return [self handleError:"Decode memory allocation failed"];
}
//--------------------------------------------------------------------
// Get a pointer to the content.
if (!CryptMsgGetParam(
hMsg, // Handle to the message
CMSG_ENCODED_MESSAGE, // Parameter type
0, // Index
pbCosignedMessageBlob, // Address for returned
&cbCosignedMessageBlob)){ // Size of the returned
return [self handleError:"Decode CMSG_ENCODED_MESSAGE #2 failed"];
}
printf("The message param (CMSG_ENCODED_MESSAGE) updated. Length is %lu.\n",(unsigned long)cbCosignedMessageBlob);
cout << "Signature was added successfully." << endl;
cout << "УЭЦП:" << endl;
for(DWORD i=0; i < cbCosignedMessageBlob; i++)
{
printf("%2.2x", pbCosignedMessageBlob[i]);
if ((i+1)%32 == 0) printf("\n");
}
if (outFilename) {
FILE *out = NULL;
out = fopen (outFilename, "wb");
if (out) {
fwrite (pbCosignedMessageBlob, cbCosignedMessageBlob, 1, out);
fclose (out);
printf ("Output file (%s) has been saved\n", outFilename);
}
else
fprintf(stderr, "Cannot open out file\n");
}
return 0;
}
Отредактировано пользователем 1 июня 2012 г. 17:09:50(UTC)
| Причина: Не указана |
ВАСИЛИЙ АНИСИМОВ Ведущий iOS разработчик в «Digital Design» www.digdes.ru |