Hi Dear all!

I'm using Visual C++ 2008 and "CryptoPP 5.5.2" version!

I've downloaded 5 programs of link:"http://www.cryptopp.com/wiki/RSA";
and 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 1024 bit modulus, accept e = 17
        CryptoPP::RSAES_OAEP_SHA_Decryptor Decryptor( rng, 1024 /*, 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 stores Genereted keys in two files named: "key.pv"  and
"key.pb"!
The contents of "key.pb" are as following:

Public key:160 bytes

30819D300D06092A864886F70D010101050003818B0030818702818100EA0E48FC0238A432E2F0316940488C4FC

A9A809919D290CDCBAF1020B1CD0ED2B9872C0A96D1746CDDC96F607A36F60E11745281DADB9BB2D8C8B1DABEDF

95453AC6E1F5EF498EAB3588E78885B515BB01A172FEF67990FD8E756184AB80E105BE4D8341BA58F8259D46A14

8AE03FCD2A26EB79AD0B4460D2F39D6428C47B1B3020111

And the contents of "key.pv" are as following:

Private key:633 bytes

30820275020100300D06092A864886F70D01010105000482025F3082025B02010002818100EA0E48FC0238A432E
2F0316940488C4FCA9A809919D290CDCBAF1020B1CD0ED2B9872C0A96D1746CDDC96F607A36F60E11745281DADB
9BB2D8C8B1DABEDF95453AC6E1F5EF498EAB3588E78885B515BB01A172FEF67990FD8E756184AB80E105BE4D834
1BA58F8259D46A148AE03FCD2A26EB79AD0B4460D2F39D6428C47B1B302011102818037126B86971C62DECBFC47
DC8798997C2FABE205E7F54F3F7B384007B15D6CE649C573C6419AB1FB7F7AB0CB680CEE99E5FD40970651CA483
3020BBAFFBC231EE5DF7421B4D88F6D01A0806087E3C340689BCCFEB122F2664878865CCEC92457ED337535907A
F5F1B315336023BB54E3D721957E1A402E491BC90DE904B8F631024100ED09DA71F8201D075907CC28ED3BAD8F4
87364E33678A108DE1F347CC1B74B412154F85D02B6EF8084BC9A77EF76F90B6DE2F124A7D19753768CB850551B
8FC9024100FCC759F4B69110149596F9C556F16A59FC97E6E14F2C69C1FC55F1FD7AF2BB4EECDDD8C111977361D
F6FEC7826B0DAFEE23D0B1E3951EA030296A2D3E31A0B9B024100A7523FD7FA71056E9932AE3B01CFC5CE8D7EA1
9153A071ABE81606EEA6DBBCA671E1A041A7903096F448E581D635DCF90245D7652B2A88EF9EF9EB83FFD738510
24100A3900D07C16CEC498DF84743747E17A3A37159286068083239DD423A9AD94C05E48F8C40B107A503181B3E
A81909062C74459DC8433500D4C570877A0B6B34AF02401BDD44E289A063382A7ABBD854737F6FDF17EC35B8E0B
40F8F1DD296A5D5C0D62B271FF77EF2AAD58335D1BD43CB43ACF35801081FA89023BDC933CE82759ACC


My first question is that why key files contents are as above,whereas
in the code defined 1024 bits(128 bytes) for modulus n?
Why does "key.pv" contain 633 bytes?!
And which part is n and wich part is d?



My second question:
Because I want to generate key pair and locate them in two byte
arrays, 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;
I need so help!

Thank you
Gary

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