English 中文(简体)
采用Microsoft CAPI
原标题:Using an SHA1 with Microsoft CAPI
  • 时间:2010-05-28 09:49:38
  •  标签:
  • c
  • cryptoapi

我有一架SHA1型散射机,我需要签署。 采用CryptSignHash(CryptSignHash())法,需要一个HCRYPTHLM来签字。 我创立了这一机制,而且由于我已经设定了实际的散射价值:

CryptCreateHash(cryptoProvider, CALG_SHA1, 0, 0, &hash);
CryptSetHashParam(hash, HP_HASHVAL, hashBytes, 0);

has有20个 by。

然而,问题在于,由这一HCRYPTHLM操作的签字是不正确的。 我发现,问题在于,消费物价指数实际上没有使用我洗tes阵阵列的所有20个tes。 出于某种原因,它认为,SHA1只是4个 by。

我写了这个小方案:

HCRYPTPROV cryptoProvider;
CryptAcquireContext(&cryptoProvider, NULL, NULL, PROV_RSA_FULL, 0);

HCRYPTHASH hash;
HCRYPTKEY keyForHash;
CryptCreateHash(cryptoProvider, CALG_SHA1, keyForHash, 0, &hash);

DWORD hashLength;
CryptGetHashParam(hash, HP_HASHSIZE, NULL, &hashLength, 0);
printf("hashLength: %d
", hashLength);

而这种印本是 has:4 !

任何人都能够解释我正在做的错事,或者为什么微软消费物价指数认为SHA1是4个 by子(32个比方),而不是20个 by子(160个比方)。

问题回答

你的法典有小的错误。 而不是

DWORD hashLength;
CryptGetHashParam(hash, HP_HASHSIZE, NULL, &hashLength, 0);
printf("hashLength: %d
", hashLength);

页: 1

DWORD hashLength, hashSize;
hashLength = sizeof(DWORD)
CryptGetHashParam(hash, HP_HASHSIZE, (PBYTE)&hashSize, &hashLength, 0);
printf("hashSize: %d
", hashSize);

届时,你们会收到20份。

在<代码>后使用<代码>CryptSignHash也必须有效。 见<代码>说明结尾处的说明。 CryptSetHashParam Function at http://msdn.microsoft.com/en-us/library/a380270(VS.85).aspx 。 我假定你刚刚犯了与<代码”相同的错误。 CryptGetHashParam(......)HP_HASHSIZE, ......) 在收回签署结果期间。 将你的代码与代码从的描述中比较 CryptSignHash function http://msdn.microsoft.com/en-us/library/a380280(VS.85).aspx





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签