On Thu, Feb 26, 2009 at 07:30, Gary <[email protected]> wrote: > I've understood that in order to accessing each element of > "PrivateKeyArray" or "PublicKeyArray" (of type SecByteBlock),I should > use "[]" operator,(e.g. PrivateKeyArray[i])! > > Is it right? >
operator[] is fine. > > I tried these two different codes in my program: > > > 1) > > byte* privkey; > byte* pubkey; > privkey=new byte[PrivateKeyArray.size()]; > pubkey=new byte[PublicKeyArray.size()]; > memcpy(privkey,PrivateKeyArray,PrivateKeyArray.size()); > memcpy(pubkey,PublicKeyArray,PublicKeyArray.size()); > > Then I would show "privkey" and "pubkey" contents in output with these > codes: > > cout<<"PrivateKeyArray is:"<<endl; > HexEncoder(new FileSink(cout)).Put(privkey,sizeof(privkey)); > cout<<endl<<endl; > cout<<"PublicKeyArray is:"<<endl; > HexEncoder(new FileSink(cout)).Put(pubkey,sizeof(pubkey)); > > But I saw this output: > > PrivateKeyArray is: > 30820275 > > PublicKeyArray is: > 30819D30 > > You saw what you should see. You only put sizeof(pubkey) into the hex encoder, so it only encoded sizeof(pubkey) bytes. pubkey is a byte *, so sizeof(pubkey) is 4 bytes on most 32-bit platforms. > > Why don't "PrivateKeyArray" and "PublicKeyArray" (of type > SecByteBlock) transfer their elements completely into "privkey" and > "pubkey" byte arrays? > They have transferred. You're only encoding 4 bytes, though. byte * has no idea what you've allocated. It's your responsibility to keep track of that. Why are you copying bytes using a for loop instead of memcpy? That should work, but it's a very silly thing to do. 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. -~----------~----~----~----~------~----~------~--~---
