All you need is in the download RSA-SSA-Filter-Test.zip<http://www.cryptopp.com/w/images/9/9b/RSA-SSA-Filter-Test.zip> - which is one this page http://www.cryptopp.com/wiki/RSA. That shoudl show you the FileFilter usage in some detail.
Best Regards David Irvine <http://maidsafe.net>maidsafe.net Limited is a limited liability company incorporated in Scotland with number SC297540. VAT Registered 889 0608 77. Registered Office: 72 Templehill, Troon, KA10 6BE. Telephone Scotland: +44 1292 750020. On Sat, Jul 21, 2012 at 12:59 PM, Michele <[email protected]>wrote: > After some attempts I solved my problems with the key pair. At now, I can > save/load and pass them to Signer/Verifier without faults. > > The Verifiy functions fails: > > void Signature::VerifySignature() > { > [...] //load the public key, calculate the digest of the file > (checked equal to that calculated in "signin function" ), load the signature > try > { > StringSource SS( digest + signature, true, new > SignatureVerificationFilter(Verifier, new StringSink(recovered), > SignatureVerificationFilter::THROW_EXCEPTION | > SignatureVerificationFilter::PUT:MESSAGE)); > } > catch(Exception e) > { > cerr << "error: " << e.what() << endl; > } > > } > > It fails because: "digital signature not valid". I'm sure signature is > valid because, at now, I run the program with only one file (testing). The > variables signature, digest and recovered are public class members. > > The variable signature, the one that causes the fault, is first saved in a > file, when my "signing function" ends, by a "saving function": > > void Signature::SaveSignature(string signed) > { > SIGNATURE = signed; > > fstream savingfile; > savingfile.open("./Signatures", fstream::out | fstream::binary); > //SIGNATURE is local variable of a "saving function" > savingfile.write(SIGNATURE.c_str(), SIGNATURE.size()); > savingfile.close(); > } > > Then is assigned to the variable signature , by a "loading function": > > string Signature::LoadSignature() > { > > fstream loadingfile; > loadingfile.open("./Signatures", fstream::in | fstream::binary); > getline(loadingfile, SIGNATURE); > loadingfile.close(); > > } > > I think that troubles could derive from saving and loadind the signature, > something about its format > I really need to fix this. So I will appreciate every suggestion that > could take me on the right track....... > > > Il giorno lunedì 16 luglio 2012 15:49:28 UTC+2, David Irvine ha scritto: > >> PV.Save(your transfomration); should do the trick. >> See this page >> http://www.cryptopp.com/docs/**ref/class_crypto_material.**html#** >> a690c7ce3e765a502b29b47a08c1a4**e7b<http://www.cryptopp.com/docs/ref/class_crypto_material.html#a690c7ce3e765a502b29b47a08c1a4e7b> >> >> Best Regards >> David Irvine >> >> >> On Mon, Jul 16, 2012 at 2:39 PM, Michele Gucciardo < >> [email protected]> wrote: >> >>> Done, now my class have this new member >>> >>> class Signature >>> { >>> [..] >>> static RSA::PrivateKey PV; >>> [..] >>> } >>> But this line >>> >>> Save(saving,queue); >>> >>> doesn't compile, because "Save is not in this scope" (i tried to make >>> SavePV a static class function but it doesn't work). Maybe I have not >>> understand your advice... >>> >>> 2012/7/16 David Irvine <[email protected]> >>> >>>> PV.Save(queue); >>>> >>>> This item is not available in the scope you are calling it in. PV is in >>>> the KeyGen scope, you should make it a static class member in this case. >>>> >>>> >>>> Best Regards >>>> David Irvine >>>> >>>> >>>> >>>> On Mon, Jul 16, 2012 at 1:32 PM, Michele >>>> <[email protected]>wrote: >>>> >>>>> After some attempts I modified the general structure of the project. >>>>> In summary: >>>>> >>>>> int main() >>>>> { >>>>> Signature Keys; >>>>> Keys.KeyGen(); >>>>> >>>>> Menu Start; //object with options for creating/filling files >>>>> Start.FileGen(); >>>>> } >>>>> >>>>> //FileGen() save file and calls CalcHash();CalcHash() calls >>>>> SignHash();SignHash() calls LoadPrivate(), gets the private key and >>>>> finally >>>>> signs the digest calculated. >>>>> >>>>> class Signature //in signature.h >>>>> {public: >>>>> string Digest; >>>>> string DigSignature; >>>>> constructor >>>>> destructor >>>>> static void KeyGen(); >>>>> void SavePrivate(string,RSA::**PrivateKey); >>>>> void LoadPrivate(); >>>>> void CalcHash(string); >>>>> void SignHash(); >>>>> }; >>>>> //I will define also SavePublic() , LoadPublic() and VerifySignature() >>>>> (when signing process will work) >>>>> >>>>> static AutoSeededRandomPool rng; >>>>> void Signature::KeyGen() >>>>> { >>>>> static RSA::PrivateKey PV; >>>>> PV.GenerateRandomWithKeySize(**rng,1536); >>>>> static RSA;;PublicKey PU; >>>>> // validation code >>>>> string saving; >>>>> saving = "//path"; >>>>> Signature Saving; >>>>> Saving.SavePV(saving, PV); >>>>> } >>>>> void Signature::SavePV(const string saving, RSA::PrivateKey PV) >>>>> { >>>>> ByteQueue queue; >>>>> PV.Save(queue); >>>>> Save(saving, queue); >>>>> } >>>>> >>>>> Now I'm in troubles because SavePV doesn't compile and I don't know >>>>> why. I think that I pass the parameters in a wrong way...... I need some >>>>> advices.... >>>>> >>>>> >>>>> Il giorno domenica 15 luglio 2012 16:13:48 UTC+2, David Irvine ha >>>>> scritto: >>>>> >>>>>> No worries. >>>>>> >>>>>> If you want the same keys though you could create a static method to >>>>>> return the generated key. As it stands you will be regenerating the key >>>>>> every time (I tink, at least if you always run GenerateKeys method which >>>>>> will overwrite the contents of the static keys). It's maybe best to >>>>>> create >>>>>> keys and pass them into your object (const) if you want to use them as I >>>>>> think you do. That way you can control which keys are in use by the >>>>>> object >>>>>> and recreate additional objects when you work with multiple keys. >>>>>> >>>>>> You will, perhaps then find it easier to create checking objects etc. >>>>>> with the same key pair. >>>>>> >>>>>> Best Regards >>>>>> David Irvine >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> On Sun, Jul 15, 2012 at 1:37 PM, Michele < >>>>>> [email protected]> wrote: >>>>>> >>>>>>> Done!! Now item 4) of my first post works fine. >>>>>>> >>>>>>> Here is a part of my Signature.cpp : >>>>>>> >>>>>>> static CryptoPP::AutoSeededRandomPool rng; //this >>>>>>> fixed rng troblues as David Irvine suggested >>>>>>> >>>>>>> void Signature::SignHash() //method declared in my >>>>>>> Signature.h file >>>>>>> { >>>>>>> [...] >>>>>>> static RSA::PrivateKey RSAprivate; >>>>>>> RSAprivate.**GenerateRandomWithK**eySize(rng,**1536); >>>>>>> >>>>>>> static RSA::PublicKey RSApublic; >>>>>>> //keys created inside the method as Fraser suggested >>>>>>> >>>>>>> //and not declared inside the class as Ingo Naumann >>>>>>> suggested >>>>>>> [...] >>>>>>> } >>>>>>> I'm not sure that the key pair is generated only once ( as I want). >>>>>>> I'm going to verify that key pair is not re-generated every time i call >>>>>>> the >>>>>>> method , because I have to sign every file with the same RSAprivate. >>>>>>> >>>>>>> Thanks Everybody!! >>>>>>> Now I'm going to work on item 5) of my first post: perform the >>>>>>> integrity check of files (created/hashed/signed). I think that, because >>>>>>> of >>>>>>> I declared my key pair as local static variables, I must implement a >>>>>>> method >>>>>>> Signature::IntegrityCheck() inside my Signature.cpp, because outside of >>>>>>> it >>>>>>> the keys will not be visible....... >>>>>>> >>>>>>> Il giorno sabato 14 luglio 2012 21:44:24 UTC+2, Michele ha scritto: >>>>>>> >>>>>>>> Ok David, now i'm deleting RNG from class members. I'm not sure >>>>>>>> that I've understand your example but i will try... >>>>>>>> >>>>>>>> Il giorno sabato 14 luglio 2012 19:08:07 UTC+2, David Irvine ha >>>>>>>> scritto: >>>>>>>>> >>>>>>>>> It seems you may not be using the RNG correctly. It's generally >>>>>>>>> preferred to have on per thread at least (or a global if you like). >>>>>>>>> i.e. >>>>>>>>> in test.cpp you will see how this was done. In your case I am not >>>>>>>>> sure you >>>>>>>>> should have a class member RNG used as you have. This can cause all >>>>>>>>> sorts >>>>>>>>> of issues with threading and protection of the os provided generator >>>>>>>>> etc. >>>>>>>>> >>>>>>>>> static OFB_Mode<AES>::Encryption s_globalRNG; >>>>>>>>> >>>>>>>>> RandomNumberGenerator & GlobalRNG() >>>>>>>>> { >>>>>>>>> return s_globalRNG; >>>>>>>>> } >>>>>>>>> >>>>>>>>> See the docs here http://www.cryptopp.com/**w**** >>>>>>>>> iki/RandomNumberGenerator<http://www.cryptopp.com/wiki/RandomNumberGenerator> >>>>>>>>> >>>>>>>>> Best Regards >>>>>>>>> David Irvine >>>>>>>>> >>>>>>>>> >>>>>>>>> On Sat, Jul 14, 2012 at 5:53 PM, Michele < >>>>>>>>> [email protected]> wrote: >>>>>>>>> >>>>>>>>>> RSA::PrivateKey RSAprivate; >>>>>>>>>> string DigitalSIgn; >>>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>> You received this message because you are subscribed to the >>>>>>> "Crypto++ Users" Google Group. >>>>>>> To unsubscribe, send an email to cryptopp-users-unsubscribe@**goo** >>>>>>> glegroups.com <[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 "Crypto++ >>>>> Users" Google Group. >>>>> To unsubscribe, send an email to cryptopp-users-unsubscribe@** >>>>> googlegroups.com <[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 "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 "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.
