Hi all.
Thank you very much dear Geoff!

>Because you're hex-ascii encoding, then stepping through and printing
>each character (which represents a nibble).

How can I represent a complete byte,not nibble?
Do we have hex-UNiCODE encoding form to show complete bytes?
If so,what and how should be it's instruction or syntax(HexEncoder
or ...)?

I need to store complete bytes in two Private and Public key arrays,
I think so: the complete bytes(not nibbles) are stored in arrays,and
just when representing,they are shown as "nibbles"!

Besides,each "ASCii" character should be represented as a byte,not
nibble!

Am I right?




>I think I'd use a ByteQueue here instead.

I changed the "RSAGenKey" code as your advice which is such the
following:

#include "stdafx.h"

// Crypto++ Includes
#include "rsa.h"
#include "osrng.h"  // PRNG
#include "queue.h"
#include "secblock.h"
//std Includes
#include <iostream>
#include <conio.h>
using namespace CryptoPP;
using namespace std;

int main()
{

        AutoSeededRandomPool rng;

        // Specify 512 bit modulus, accept e = 17
        RSAES_OAEP_SHA_Decryptor Decryptor( rng, 512 /*, e */ );

       // encode into a ByteQueue instead of an ArraySink to find out
the size
        ByteQueue privq;
        Decryptor.DEREncode(privq);

       //Allocate an array the size of the DER-encoded private key.
        SecByteBlock PrivateKeyArray((unsigned int)
privq.MaxRetrievable());

       // copy the bytes into the array.
        privq.Get((byte*)PrivateKeyArray,PrivateKeyArray.size());



        RSAES_OAEP_SHA_Encryptor Encryptor(Decryptor);
        ByteQueue pubq;
        Encryptor.DEREncode(pubq);
        SecByteBlock PublicKeyArray((unsigned int)pubq.MaxRetrievable
());
        pubq.Get((byte*)publicKeyArray,publicKeyArray.size());

        _getch();
          return 0;
}

After compiling it,I got these errors:

------ Build started: Project: RSAKeyGen, Configuration: Debug Win32
------
Compiling...
RSAKeyGen.cpp
d:\rsakeygen.cpp(43) : error C2065: 'publicKeyArray' : undeclared
identifier
d:\rsakeygen.cpp(43) : error C2065: 'publicKeyArray' : undeclared
identifier
d:\rsakeygen.cpp(43) : error C2228: left of '.size' must have class/
struct/union type is ''unknown-type''

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

Why can't the compiler identify "publicKeyArray"?, whereas I have
declared it in this line:

SecByteBlock PublicKeyArray((unsigned int)pubq.MaxRetrievable());



I will thank you so much,if you help me again?!

Best Regards.
Gary

On Feb 23, 8:22 am, Geoff Beier <[email protected]> wrote:
> 2009/2/22 Gary <[email protected]>:> 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 you're hex-ascii encoding, then stepping through and printing
> each character (which represents a nibble).
>
>
>
> > 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:
>
> I think I'd use a ByteQueue here instead. Encode each of your keys
> into a ByteQueue, call MaxRetrievable() to find out how many bytes are
> there, use that to allocate your array, then use the Get() method on
> the ByteQueue to dump the bytes into your array. So it'd look
> something like:
>
> RSAES_OAEP_SHA_Encryptor Encryptor(Decryptor);
> // encode into a ByteQueue instead of an ArraySink to find out the size
> ByteQueue pubq;
> Encryptor.DEREncode(pubq);
> // allocate an array the size of the DER-encoded public key.
> SecByteBlock publicKeyArray(pubq.MaxRetrievable());
> // copy the bytes into the array.
> pubq.Get(publicKeyArray,publicKeyArray.size());
>
> (* Warning: the above was typed into my mail window; I didn't compile
> it. Review the reference if there's any trouble compiling it!)
>
> and pubArray would then contain the bytes of your DER-encoded key
> material. If you then wanted to print those to screen, you'd need to
> encode them first to be sure they're printable. The SHA example I
> posted earlier shows one way to do that.
>
> Good luck,
>
> Geoff
--~--~---------~--~----~------------~-------~--~----~
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