使用SHA-512为哈希创建CMS中的分离签名

时间:2018-06-08 08:50:25

标签: c++ cryptography digital-signature cryptoapi asn1

我有内容和CMS带有分离签名(密钥算法 - SHA-256)和 我使用密钥算法SHA-512向CMS添加一个签名。但是当使用CryptoApi添加时,函数if (this.context.options.length === 0) { this.context.someClassWithBean.someBean.forEach(() => { this.context.options.push(false); }); } 将返回CryptMsgControl(hMsg, 0, CMSG_CTRL_ADD_SIGNER, &SignerEncodeInfo)

原因是CMS中digestAlgoritm: ASN.1 structure

中不存在SHA-512

如果我使用ASN.1编辑器添加SHA-512,将添加签名者信息:ASN.1 after insert

是否可以直接使用CryptoApi添加此块或SignerInfo,还是只能通过编辑ASN.1来实现?

1 个答案:

答案 0 :(得分:0)

我找到了解决方法。

我创建了一个包含算法但不包含签名者信息和证书的模板。可以使用asn1编辑器或CryptoApi(使用CryptMsgOpenToDecodeCryptMsgControl(..., CMSG_CTRL_DEL_SIGNER, ...)来完成) 然后需要将签名者信息和证书从当前签名转移到上面创建的模板

PCMSG_CMS_SIGNER_INFO pSignerInfo;
DWORD cbSignerInfo;
CryptMsgGetParam(hMsg2, CMSG_CMS_SIGNER_INFO_PARAM, 0, NULL, &cbSignerInfo);
pSignerInfo = (PCMSG_CMS_SIGNER_INFO)LocalAlloc(LPTR, cbSignerInfo);
CryptMsgGetParam(hMsg2, CMSG_CMS_SIGNER_INFO_PARAM, 0, (PVOID)pSignerInfo, &cbSignerInfo);

CryptMsgControl(hMsg, 0, CMSG_CTRL_ADD_CMS_SIGNER_INFO, pSignerInfo);

DWORD cbCertInfo;
CryptMsgGetParam(hMsg2, CMSG_CERT_PARAM, 0, NULL, &cbCertInfo);
std::vector<BYTE> pCertInfo(cbCertInfo);
CryptMsgGetParam(hMsg2, CMSG_CERT_PARAM, 0, &pCertInfo[0], &cbCertInfo);

CRYPT_INTEGER_BLOB certBlob;
memset(&certBlob, 0, sizeof(CRYPT_INTEGER_BLOB));
certBlob.cbData = cbCertInfo;
certBlob.pbData = &pCertInfo[0];
CryptMsgControl(hMsg, 0, CMSG_CTRL_ADD_CERT, &certBlob);

之后,您可以添加一个新签名。

相关问题