Hi Dear Jeff and Thank you very much!

The link:http://www.cryptopp.com/wiki/RSA. was very useful for me,I
built all 5 programs successfully!
Now my questions:(I have two questions!)

The "RSAKeyGen" program is as below:
#include "stdafx.h"

// Crypto++ Includes
#include "rsa.h"
#include "osrng.h"  // PRNG
#include "hex.h"    // Hex Encoder/Decoder
#include "files.h"  // File Source and Sink

int main(int argc, char* argv[])
{
    try
    {
        std::string PrivateKeyFile = "key.pv";
        std::string PublicKeyFile  = "key.pb";

        CryptoPP::AutoSeededRandomPool rng;

        // Specify 512 bit modulus, accept e = 17
        CryptoPP::RSAES_OAEP_SHA_Decryptor Decryptor( rng, 512 /*, e
*/ );
        CryptoPP::HexEncoder privFile(new
            CryptoPP::FileSink( PrivateKeyFile.c_str() )
        ); // Hex Encoder

        Decryptor.DEREncode(privFile);
        privFile.MessageEnd();

        CryptoPP:: RSAES_OAEP_SHA_Encryptor Encryptor(Decryptor);
        CryptoPP::HexEncoder pubFile(new
            CryptoPP::FileSink( PublicKeyFile.c_str() )
        ); // Hex Encoder
        Encryptor.DEREncode(pubFile);
             pubFile.MessageEnd();
    }

    catch( CryptoPP::Exception& e ) {
        std::cerr << "Error: " << e.what() << std::endl;
    }

    catch (...) {
        std::cerr << "Unknown Error" << std::endl;
    }

        return 0;
}

Which locates Genereted keys in two files named: "key.pv"  and
"key.pb"
The contents of "key.pb" is 92 bytes and the contents of "key.pv" is
344 bytes!
My first question is that why key files contents are as above,whereas
in the code defined 512 bits(64 bytes) for modulus?
Why does "key.pv" contain 344 bytes?!
(What is it's meaning? Does that mean 280 bytes for "d" parameter of
"private key"?



My second question:
Because I want to generate key pair and locate them in two byte
arrays,as your advice, I used of "ArraySink" instead of "FileSink" and
changed the above code as below:


#include "stdafx.h"

// Crypto++ Includes
#include "rsa.h"
#include "osrng.h"  // PRNG
#include "hex.h"    // Hex Encoder/Decoder
#include "files.h"  // File Source and Sink
#include "filters.h" //Array Source and  Sink

int main(int argc, char* argv[])
{
    try
    {
                byte* privatekey;
                byte* publickey;
        //std::string PrivateKeyFile = "key.pv";
        //std::string PublicKeyFile  = "key.pb";

        CryptoPP::AutoSeededRandomPool rng;

        // Specify 512 bit modulus, accept e = 17
        CryptoPP::RSAES_OAEP_SHA_Decryptor Decryptor( rng, 512 /*, e
*/ );
        CryptoPP::HexEncoder privArray(new
            CryptoPP::ArraySink(privatekey,sizeof(privatekey))
        ); // Hex Encoder

        Decryptor.DEREncode(privArray);
        privArray.MessageEnd();

        CryptoPP:: RSAES_OAEP_SHA_Encryptor Encryptor(Decryptor);
        CryptoPP::HexEncoder pubArray(new
            CryptoPP::ArraySink( publickey, sizeof(publickey))
        ); // Hex Encoder
        Encryptor.DEREncode(pubArray);
             pubArray.MessageEnd();

    }

    catch( CryptoPP::Exception& e ) {
        std::cerr << "Error: " << e.what() << std::endl;

    }

    catch (...) {
        std::cerr << "Unknown Error" << std::endl;
    }

        return 0;
}

After compile,I got this output:(3 warnings and 0 error!)

------ Build started: Project: RSAKeyGen, Configuration: Debug Win32
------
Compiling...
RSAKeyGen.cpp
d:\rsakeygen.cpp(26) : warning C4700: uninitialized local variable
'privatekey' used
d:\rsakeygen.cpp(34) : warning C4700: uninitialized local variable
'publickey' used

Linking...
RSAKeyGen.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/
INCREMENTAL:NO'


RSAKeyGen - 0 error(s), 3 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped
==========


But after running it's .exe file,I got runtime error!

I want to show the contents of  two key arrays in output and can use
of their contents, but I don't know what should I do?
Which section of the changed code is wrong and how can I see the
contents of arrays and use or manipulate  them?

I'll greatly appreciate you, if help me again;
Good Luck!
Gary







On Feb 5, 12:39 am, Jeffrey Walton <[email protected]> wrote:
> Hi Gary,
>
> You migh also want to look at the Wiki:http://www.cryptopp.com/wiki/RSA.
>
> > Also,this code locates Generated keys in a file,but I want to locate
> > generated keys in two byte arrays.
>
> Use either a StringSource/StringSink or ArraySource/ArraySink rather
> than a FIleSource/FileSink.
>
> Jeff
>
> On 2/4/09, Gary <[email protected]> wrote:
>
>
>
>
>
> > Hi dear friends!
> > I'm using "Visual C++ 2008" and "CryptoPP 5.5.2" version!
> > I want to generate  an RSA-1024 bit keypair for sign and verify in a
> > function of my project,there is a sample code of "generate an RSA
> > keypair and save it" in the "Crypto++ user's guide" by denis bider as
> > below:
>
> > [ SNIP ]
>
> > But this code is applied for previous versions of "Cryptopp" library
> > and doesn't match with "CryptoPP 5.5.2" version!
> > Also,this code locates Generated keys in a file,but I want to locate
> > generated keys in two byte arrays.
> > I've studied "Reference" and I have found that should use of
> > "BufferedTransformation" type,but I don't know how to use it,because I
> > have no sample code of using it.
> > So far,I have not had any experience to implementing a cryptographic
> > scheme using "Cryptopp" library and really don't know what should I
> > do?!
> > I have really spent so much time on it, but I couldn't write any code!
> > I greatly ask you help me with some sample codes about "generate
> > RSA-1024 keypair" and "sign/verify with RSA-1024 and SHA1 hash
> > algorithm"
> > I'm so new to "Cryptopp" library and need to help as soon as
> > possible,hence ask you help me!
> > Thanks in Advance.
--~--~---------~--~----~------------~-------~--~----~
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