On Wednesday, August 21, 2013 2:51:52 AM UTC-4, robert.hegner wrote:
>
> Am Montag, 19. August 2013 03:45:41 UTC+2 schrieb Jeffrey Walton:
>>
>>
>>
>> On Friday, August 16, 2013 3:28:52 AM UTC-4, robert.hegner wrote:
>>>
>>> Hi there!
>>>
>>> I have a binary file with the following content
>>>
>>>    - length of the signature as an uint32
>>>    - signature
>>>    - length of the data as an uint32
>>>    - data
>>>
>>> and I'd like to verify the data. First I create my verifier like this:
>>>
>>> CryptoPP::RSA::PublicKey publicKey;
>>> CryptoPP::Integer n(PUBLIC_KEY_MODULUS, sizeof(PUBLIC_KEY_MODULUS));
>>> CryptoPP::Integer e(PUBLIC_KEY_EXPONENT, sizeof(PUBLIC_KEY_EXPONENT));
>>> publicKey.Initialize(n, e);
>>> CryptoPP::RSASS<CryptoPP::PKCS1v15, CryptoPP::SHA1>::Verifier 
>>> verifier(publicKey);
>>>
>>  ...
>>
>> But it returns false. I also tried this:
>>>
>>> CryptoPP::FileSource fileSource(packagePath.c_str(), true);
>>> CryptoPP::VerifierFilter verifierFilter(verifier);
>>> uint32_t len;
>>> fileSource.GetWord32(len);
>>> fileSource.TransferTo(verifierFilter, len);
>>> fileSource.GetWord32(len);
>>> fileSource.TransferTo(verifierFilter, len);
>>> bool valid = verifierFilter.GetLastResult();
>>>
>> I also forgot to mention.... 
>>
>> By default, SignatureVerificationFilter uses SIGNATURE_AT_END. If you 
>> want to insert the signature first, you should use SIGNATURE_AT_BEGIN. See 
>> http://www.cryptopp.com/wiki/SignatureVerificationFilter.
>>
>> Jeff 
>>
>
>
>
> Thanks Jeff for your help!
> I tried both your suggestions but it still doesn't work. To make sure that 
> my data is correct I also tried (with the same verifier as in my original 
> post) this solution without using filters:
>
> std::ifstream ifs(packagePath.c_str(), std::ios::in + std::ios::binary);
> uint32_t signatureLen;
> ifs.read((char*)&signatureLen, sizeof(uint32_t));
> boost::scoped_array<uint8_t> signature(new uint8_t[signatureLen]);
> ifs.read((char*)signature.get(), signatureLen);
> uint32_t dataLen;
> ifs.read((char*)&dataLen, sizeof(uint32_t));
> boost::scoped_array<uint8_t> data(new uint8_t[dataLen]);
> ifs.read((char*)data.get(), dataLen);
> bool valid = verifier.VerifyMessage(data.get(), dataLen, signature.get(), 
> signatureLen);
>  
> This works fine!
> But I would still like to use the FileSource / VerifierFilter approach for 
> working with my file. What else could be the problem with my original code??
>
Have you tried SIGNATURE_AT_BEGIN and SIGNATURE_AT_END?

Otherwise, I have no idea (but I did not run any code either). Try calling 
MessageEnd() on the verifier before calling GetLastResult().

Jeff 

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to