Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

computing hash from a pkcs7 signature

196 views
Skip to first unread message

Param

unread,
Jun 29, 2005, 2:45:01 AM6/29/05
to
Hi,
How to get the hash from a pkcs7 signature.
Is there any CryptoAPI for this.
What about the CryptMsgGetParam()?
If this is the correct API , then what I have to pass dwParamType?
Thanx in advance

Michel Gallant

unread,
Jun 29, 2005, 9:06:13 AM6/29/05
to
CMSG_HASH_DATA_PARAM.
Don't forget that this hash value will include both the content signed, as well
as any authenticated attributes, if present.
- Mitch Gallant

"Param" <Pa...@discussions.microsoft.com> wrote in message news:1A6A06B0-0021-440A...@microsoft.com...

Param

unread,
Jun 30, 2005, 1:08:01 AM6/30/05
to
thanx for ur reply,
here is the code snippet.

1)hMsg = CryptMsgOpenToDecode(MY_ENCODING_TYPE,0,0,0,NULL,NULL);

2)if(!(CryptMsgUpdate(hMsg,pbData,cbData,TRUE)))
{

}
3)if(!(CryptMsgGetParam(hMsg,CMSG_HASH_DATA_PARAM,0,NULL,&cbHash)))
{

}

4)if(!(CryptMsgGetParam(hMsg,CMSG_HASH_DATA_PARAM,0,pbHash,&cbHash)))
{

}

in step 3 i am getting CRYPT_E_INVALID_MSG_TYPE error.
but this message is pkcs7 signed message and also i am able to verify the
signature using other tools.Is there any wrong in this?
thanx

Param

unread,
Jun 30, 2005, 6:58:05 AM6/30/05
to
FYI
if(!CryptMsgGetParam(
hMsg, // Handle to the message
CMSG_TYPE_PARAM, // Parameter type
0, // Index
&dwMsgType, // Address for returned information
&cbData)) // Size of the returned information
{

}

in the above i am getting dwMsgType as CMSG_SIGNED for the same message.
thanx

Michel Gallant

unread,
Jun 30, 2005, 9:31:59 AM6/30/05
to
Send me a copy of a signed message blob you are using.
- Mitch

"Param" <Pa...@discussions.microsoft.com> wrote in message news:FB8A92CD-A333-465A...@microsoft.com...

Michel Gallant

unread,
Jul 1, 2005, 3:26:02 PM7/1/05
to
Actually, i think the correct parameter is CMSG_COMPUTED_HASH_PARAM.

And, that only seems to return the SHA1 hash value for the following cases:
(1) a pkcs7 signature with the content INCLUDED (i.e. a non-null data sequence following
that SHA1 sequence.
(2) a detached signature WITH authenticated attributes, where the hash returned is that of
all the authenticated attributes (binary DER sequences).

I don't know exactly what the CMSG_HASH_DATA_PARAM is supposed to return, but
it for the cases that i tested, it always returns a byte buffer of zero size!

- Mitch Gallant

"Param" <Pa...@discussions.microsoft.com> wrote in message news:FB8A92CD-A333-465A...@microsoft.com...

Michel Gallant

unread,
Jul 5, 2005, 9:13:45 AM7/5/05
to
Another approach you can use to verify a detached pkcs#7 signature, if there are issues
with data size limitations in higher level capi verification functions is:

(1) Get the pkcs#1 "signature" (encrypted hash) from your PKCS#7 signed message using:
CryptMsgGetParam(hMsg, CMSG_ENCRYPTED_DIGEST ..... This returns encrypted hash
in big-endian order.

(2) Next, use the lower level signature verification function CryptVerifySignature(...) which
uses these pkcs#1 signatures (not CMS/pkcs#7). This uses little-endian ordered pkcs1
signature blob, so reverse the bytes from (1). You need to compute the hash (which
you can do via streaming, for any size file) and get the publickey handle, no problem, for this function.

CryptVerifySignature(...) compares recomputed hash with the hash in the pkcs#1 signature,
and returns the validity status of the signature.

Combine your CryptMsgGetParam(..) code with the CryptVerifySignature code here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/seccrypto/security/example_c_program_signing_a_hash_and_verifying_the_hash_signature.asp

There should be no file-size limitations in this mixed approach to verifying
a given detached pkcs#7 signature, with data of any size, using CryptoAPI.

- Mitch Gallant

"Michel Gallant" <neu...@istar.ca> wrote in message news:%23feeNLn...@tk2msftngp13.phx.gbl...

0 new messages