Hi Sameh,

Wei has a lot of sample code (including RSA) in benchmark and
validate.cpp files. In addition, his Wiki pages has some RSA which can
be found at http://www.cryptopp.com/wiki/RSA.

Sorry, I'm not familiar with the Ergo samples.

Jeff

On 5/12/07, Sameh <[EMAIL PROTECTED]> wrote:
>
> I'm new to crypto++, and i believe i'm doing something wrong.
>
> I'm just trying to encrypt/decrypt files using RSA. I have followed a
> simple tutorial at ergo (http://ergo.rydlr.net/?p=53). My encryption
> phase is working (I think!), but when it tries to decrypt, it gives me
> an error (digging for the error, i found out it was an
> invalidciphertext), this is making me think that my encryption is not
> working correct. Following is a listing for my main (it both encrypts
> and decrypts):
>
> /
> ********************************************************************************************************************************/
>        string keyDir = "c:/keys";
>        string keyFile = keyDir + "/" + "pubring.g";
> FileSource pubFile(keyFile.c_str(), true, new HexDecoder);
> RSAES_OAEP_SHA_Encryptor pub(pubFile);
>
>        string MsgFileS = keyDir + "/" + "Message.txt";
> ifstream MsgFile(MsgFileS.c_str());
>
> ofstream Encoded("C:/keys/Encoded.txt");
> FileSink fsout(Encoded);
>
> AutoSeededRandomPool rngKey;
> byte randomBytesKey[16];
> rngKey.GenerateBlock(randomBytesKey, sizeof(randomBytesKey));
>
> char *key = (char*)randomBytesKey;
> string hexkey;
> StringSource(key, true, new HexEncoder(new StringSink(hexkey)));
>
> AutoSeededRandomPool rngSeed;
> byte randomBytesSeed[16];
> rngSeed.GenerateBlock(randomBytesSeed, sizeof(randomBytesSeed));
>
> StringSource ("__BEGIN_KEY__n", true, new ChannelSwitch(fsout));
> StringSource (hexkey, true, new PK_EncryptorFilter(rngSeed, pub, new
> Base64Encoder(new ChannelSwitch(fsout))));
> StringSource ("__END_KEY__n", true, new ChannelSwitch(fsout));
>
> StringSource ("__BEGIN_DATA__n", true, new ChannelSwitch(fsout));
> FileSource (MsgFile, true, new DefaultEncryptorWithMAC(hexkey.c_str(),
> new Base64Encoder(new ChannelSwitch(fsout))));
> StringSource ("__END_DATA__n", true, new ChannelSwitch(fsout));
> Encoded.close();
> MsgFile.close();
>
> ifstream EncodedT("C:/keys/Encoded.txt");
> keyFile = keyDir + "/" + "secring.g";
>
> FileSource privFile(keyFile.c_str(), true, new HexDecoder);
> RSAES_OAEP_SHA_Decryptor priv(privFile);
> AutoSeededRandomPool rngSeed2;
> FileSource f(EncodedT, true, new Base64Decoder(new
> PK_DecryptorFilter(rngSeed2, priv, new FileSink(cout))));
> /
> ********************************************************************************************************************************/
>
> obviously the last line in my program is the one giving me the
> trouble. Here is my pubring.g:
>
> 30819D300D06092A864886F70D010101050003818B0030818702818100B8E6CCD331960E84C67E56AFCBF1A98A8ACE8AE26BC16C2A0B0948B49B01AF5968933A1D0DBB74F4ECC207B79FBD3C14AF4C731D7C77C3A9283EA4CC9845C5F3205375F7CB4028BE2EAB6863BFCB143853BB76363FD9D71F364DB511E134F92D42A7B68B2642A06D76003BA3D9C5C3F056F11DF9F9987F2898A11AD7D001E511020111
>
> /
> ********************************************************************************************************************************/
>
>
> and here is my secring.g (not sure they are necessary but just in
> case):
> 30820274020100300D06092A864886F70D01010105000482025E3082025A02010002818100B8E6CCD331960E84C67E56AFCBF1A98A8ACE8AE26BC16C2A0B0948B49B01AF5968933A1D0DBB74F4ECC207B79FBD3C14AF4C731D7C77C3A9283EA4CC9845C5F3205375F7CB4028BE2EAB6863BFCB143853BB76363FD9D71F364DB511E134F92D42A7B68B2642A06D76003BA3D9C5C3F056F11DF9F9987F2898A11AD7D001E51102011102818001960EEEFCF971B173E61A7818A6C76A4958FCCC9BE79EBB574F73C2CDE0F4A437CC8E9DBD4B55653D02EB5C3DEB594CB9F970AC7CFD433F4149525ADA6780212139D21874076B1907D73E9CBEC6A677AAE575A4F4CA169DFF0F116F05694D21D10001440A87BF6C537F2EF34F02107D8C33469D9B41316F1B49B9613F4E1191024100F4025742C0DBD1DA8B0B90121C0E81F50518F9C03275FA6D5C7B043EEE8091D09B00AF4C70F55EA3DED15DA9A8AC54DA1E4F4F7DE8E331F2D4ACC27507205DB1024100C1FCE149594CB6EB7F535583E947A057C6260F0FBA82B4BFFE63E5207BE5DA3FC55D4F1E7C0F3BE391D733C1A4BB1158AA6D146E8305A60BA01912F5F554F561024100E5A7D9A83D0B1FDCBF19F101FC49E3B96E359FC3F341DCA329DD312C2BC44D0091E286DE886E7730D1B5FDCCDAFC8C1894FF59DFEA3F3E11B91B115F15C41BF1024066B30DDB89A1158BBBE0D2EB7B8045D41D9BAD9EEA453283C2E9976B8CE31930D1E61AD3E7535BF0F2DB57A2C09F456B2D0C92589FB7B24263D10A09BE1DEB510240477C2AA2AC9C99D19851C18A8568F95884AD3E3F9BB0BCE1386D3B2783B08B78DB2DE7F1F0158BB185FE3528A8ECA2D314F5681F9BBA51E08A877AE539BBFDD5
>
> /
> ********************************************************************************************************************************/
>
> Here is the message i'm encrypting:
>
> // test.cpp - written and placed in the public domain by Wei Dai
>
> /
> ********************************************************************************************************************************/
>
> Finall, here is my encrypted file:
>
> __BEGIN_KEY__nHUMmfq05CLzvsqVFeC38UT+xfDg2Fu5qra5gm4N/Y27IowYw1EElX9v/
> vJ/nDIMmqXjUGTrU
> KNywcNbssTZXnjzikL4ITIXrEAqYEN8MEt6t
> +CQb7OId1oz8ZgkLNopjKq9CczUB3VKv2nKG
> 92XjVvqtSjUxVcx3gw707w/iTgI=
> __END_KEY__n__BEGIN_DATA__nGE2k1L/
> 6nQc4P6zhNbUL29Fgt0zv1bdTvlyrxGU4U7wzD1EscnkjIu7D7PfR85Cw2d3GQ1OR
> 3Y3eokyrfGSkSX4nPqMQy5+vJBMvzm2m+o95y3JUuTxMRUK46SmXHeREg/qIy918epQ=
> __END_DATA__n
>
> /
> ********************************************************************************************************************************/
>
> Sorry for the long message, but i didn't want to miss anything (i'm
> working visual .net 2005 just in case). Any suggestions??
>
> Thanks for the help,
> Sameh
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---

Reply via email to