开发者

Sign Hash with windows Cryptography functions C++

I am using visual studio 2005 and C++.

Hello, I use a very good function to sign CryptSignMessage. With this I can specify signed attributes, signatory's certificate, unsigned attributes, if is detached and so on.

However, one of the parameters of this function is the "original document", which according to the documentation this creates a hash of the specified content and signs the hash

I wonder if I can create a signature equivalent, using only the hash of the document. I do not have the document, I have only the hash.

I found CryptSignHash, but this function does not allow specify parameters as signed attributes or unsigned attributes and/or signatory's certificate. According to my research, this function seems to return a PKCS#1, where later I should set up a structure of signature PKCS#7. So would be grateful to know if there is any way to make a signature with the hash and if there is a way to create a PKCS#7 structure from PKCS#1 using windows functions. Or Is there any way to sign only the hash, which is as simple as using CryptSignMessage?

#update 1

The CryptSignHash does not return PKCS#1. Return a byte array with PKCS#1 padding.

I tried开发者_Python百科 to use CryptMsgOpenToEncode and CryptSignMessage passing the contents as "NULL" and adding the hash to signed attributes, they calculate the hash of empty.

Is there any way to do this using Windows functions?


Its a bad idea to sign a hash without calculating the hash yourself. See Sign a Hash, Generate digest and signature separately, and MFSA 2006-60.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜