Hi all!
I changed RSAGenKey code to store keypair into two byte array named
"PrivateKeyArray" and
"PublicKeyArray", then built the program:

The code is:

#include "stdafx.h"

// Crypto++ Includes
#include "rsa.h"
#include "osrng.h"  // PRNG
#include "hex.h"    // Hex Encoder/Decoder
#include "filters.h" // String Source and Sink
//std Includes
#include <iostream>
#include <conio.h>
using namespace CryptoPP;
using namespace std;

int main()
{


         byte PrivateKeyArray[256];
        byte PublicKeyArray[256];


        AutoSeededRandomPool rng;

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

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

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

                 cout<<"PrivateKeyArray is:"<<endl;
                 for(int i=0;i<sizeof(PrivateKeyArray);i++)
                 cout<<PrivateKeyArray[i]<<" | ";

                 cout<<"\n\nPublicKeyArray is:"<<endl;
                 for(int i=0;i<sizeof(PublicKeyArray);i++)
                 cout<<PublicKeyArray[i]<<" | ";
                 getch();
        return 0;
}


After Building,the output on console, was such below:

PrivateKeyArray is:
3 | 0 | 8 | 2 | 0 | 1 | 5 | 3 | 0 | 2 | 0 | 1 | 0 | 0 | 3 | 0 | 0 | D
| 0 | 6 |
0 | 9 | 2 | A | 8 | 6 | 4 | 8 | 8 | 6 | F | 7 | 0 | D | 0 | 1 | 0 | 1
| 0 | 1 |
0 | 5 | 0 | 0 | 0 | 4 | 8 | 2 | 0 | 1 | 3 | D | 3 | 0 | 8 | 2 | 0 | 1
| 3 | 9 |
0 | 2 | 0 | 1 | 0 | 0 | 0 | 2 | 4 | 1 | 0 | 0 | C | 2 | 7 | 1 | 8 | F
| 6 | 1 |
B | F | E | 4 | E | A | F | C | F | A | 8 | 7 | 7 | F | F | 8 | A | 3
| 9 | C |
F | 2 | 7 | C | B | A | 4 | E | 6 | 7 | 4 | A | 1 | 9 | B | 9 | A | 1
| E | 4 |
3 | 7 | 9 | 0 | 1 | 9 | F | 4 | 8 | 1 | 6 | 0 | 8 | 0 | 6 | 7 | D | D
| 0 | B |
5 | C | 9 | E | 1 | B | B | F | B | 5 | C | 1 | A | E | 8 | E | 5 | 0
| 8 | 5 |
E | 6 | D | 7 | 0 | 1 | B | 4 | 4 | 7 | 5 | 2 | 0 | 9 | A | 9 | 8 | 2
| 8 | 6 |
C | F | 9 | 2 | 2 | 7 | 7 | 2 | B | F | 4 | 8 | 6 | E | A | 7 | 3 | 8
| 9 | 7 |
0 | 2 | 0 | 1 | 1 | 1 | 0 | 2 | 4 | 0 | 1 | C | 9 | 8 | 3 | A | B | B
| 8 | D |
2 | 9 | 3 | 1 | 9 | D | A | C | 5 | F | 3 | 8 | 7 | 7 | 6 | 3 | 5 | A
| D | 8 |
5 | D | A | 2 | E | D | 6 | 9 | 8 | A | E | 5 | A | A | 5 | B |

PublicKeyArray is:
3 | 0 | 5 | A | 3 | 0 | 0 | D | 0 | 6 | 0 | 9 | 2 | A | 8 | 6 | 4 | 8
| 8 | 6 |
F | 7 | 0 | D | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 5 | 0 | 0 | 0 | 3 | 4 | 9
| 0 | 0 |
3 | 0 | 4 | 6 | 0 | 2 | 4 | 1 | 0 | 0 | C | 2 | 7 | 1 | 8 | F | 6 | 1
| B | F |
E | 4 | E | A | F | C | F | A | 8 | 7 | 7 | F | F | 8 | A | 3 | 9 | C
| F | 2 |
7 | C | B | A | 4 | E | 6 | 7 | 4 | A | 1 | 9 | B | 9 | A | 1 | E | 4
| 3 | 7 |
9 | 0 | 1 | 9 | F | 4 | 8 | 1 | 6 | 0 | 8 | 0 | 6 | 7 | D | D | 0 | B
| 5 | C |
9 | E | 1 | B | B | F | B | 5 | C | 1 | A | E | 8 | E | 5 | 0 | 8 | 5
| E | 6 |
D | 7 | 0 | 1 | B | 4 | 4 | 7 | 5 | 2 | 0 | 9 | A | 9 | 8 | 2 | 8 | 6
| C | F |
9 | 2 | 2 | 7 | 7 | 2 | B | F | 4 | 8 | 6 | E | A | 7 | 3 | 8 | 9 | 7
| 0 | 2 |
0 | 1 | 1 | 1 | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠
| ╠ | ╠ |
╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠
| ╠ | ╠ |
╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠
| ╠ | ╠ |
╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ | ╠ |

I've seperated generated bytes with " | " character!

Questions:

My first question is that why does each byte is shown as "one
Hexadecimal digit"?
For example, in first byte of "PrivateKeyArray", I see only "3" digit
instead of two Hex digit(one byte)?


Because I exactly don't know length of Generated Private and Public
keys,I decided to define
" byte* " instead of array for two key arrays and changed some lines
of the above code as below:

byte* PrivateKeyArray;
byte* PublicKeyArray;

but I have problems in these sections:

ArraySink(PrivateKeyArray,sizeof(PrivateKeyArray))
ArraySink(PublicKeyArray,sizeof(PublicKeyArray))

My second question:
I exactly don't know what should I replace in second argument of
"ArraySink"?
Since I don't know "PrivateKeyArray" and "PublicKeyArray" sizes yet!!
And after compiling this changed code,I got these warnings and then a
runtime error:

d:\rsakeygen.cpp(29) : warning C4700: uninitialized local variable
'PrivateKeyArray' used
d:rsakeygen.cpp(37) : warning C4700: uninitialized local variable
'PublicKeyArray' used

How can I modify this problem,I mean what should I set as 2th argument
of "ArraySink"?
Do I first assign memory with "new" operator to them or define a
default size for each byte pointer?

Very respectfully!
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