When I use Encode, now the private key length is 40 byte, when
HexDecode it, it's exactly 20 byte, that is, 160 bit.

Thank you very much!

harry
On Apr 17, 11:42 am, "Wei Dai" <[EMAIL PROTECTED]> wrote:
> The sizes are doubled because you're using HexEncoder. For the private key,
> you can save a few more bytes by using the Encode() method instead of
> DEREncode().
>
>
>
> ----- Original Message -----
> From: "Harry" <[EMAIL PROTECTED]>
> To: "Crypto++ Users" <[EMAIL PROTECTED]>
> Sent: Sunday, April 15, 2007 11:49 PM
> Subject: Re: How to save public key and private key for ECC?
>
> > Dear Wei,
> > Thank you for your quick reply.
>
> > The code you posted did a greate job!
>
> > Now the length for public.key file is 42 byte, and the length for the
> > private.key is 46 byte.  They are much smaller than before, but i
> > still don't know why these two length show that we use a ecc 160 bit
> > crypography. I thought in a very stupid way that a key length of 20
> > byte shows that we use a 160 bit crypography.
>
> > Any suggestion or explanation from you is greatly apprieciated.
>
> > Best Wishes,
>
> > Harry
>
> > On Apr 16, 1:16 pm, "Wei Dai" <[EMAIL PROTECTED]> wrote:
> >> To minimize the size of public and private keys, what you need to do is
> >> encode only the private exponent of the private key, and the public point
> >> of
> >> the public key. Try this:
>
> >>  // save private exponent
> >>  PrivateKey.GetPrivateExponent().DEREncode(privFile);
>
> >>  // load private exponent
> >>  Integer x;
> >>  x.BERDecode(privFile);
>
> >> PrivateKey.AccessGroupParameters().Initialize(CryptoPP::ASN1::secp160k1());
> >>  PrivateKey.SetPrivateExponent(x);
>
> >>  // save public element
> >>  PublicKey.GetGroupParameters().GetCurve().EncodePoint(pubFile,
> >> PublicKey.GetPublicElement(), true);
>
> >>  // load public element
> >>  ECP::Point p;
>
> >> PublicKey.AccessGroupParameters().Initialize(CryptoPP::ASN1::secp160k1());
> >>  PublicKey.GetGroupParameters().GetCurve().DecodePoint(p, pubFile,
> >> PublicKey.GetGroupParameters().GetCurve().EncodedPointSize(true));
> >>  PublicKey.SetPublicElement(p);
>
> >> ----- Original Message -----
> >> From: "Harry" <[EMAIL PROTECTED]>
> >> To: "Crypto++ Users" <[EMAIL PROTECTED]>
> >> Sent: Sunday, April 15, 2007 9:18 PM
> >> Subject: How to save public key and private key for ECC?
>
> >> > Hi, all Crypto++ Users,
>
> >> > I used secp160k1 to create a pair of publick/private key into files,
> >> > the length for private.key is 408 byte and for public.key is 428 byte.
> >> > How can I convert the file into a 160bit length, that is, 20 byte
> >> > lengthstring?
>
> >> > This is the code:
> >> > char* seed = "1234567890";
> >> >        char* privFilename = "Private.key";
> >> > char* pubFilename = "Public.key";
>
> >> > CryptoPP::ECIES< CryptoPP::ECP >::PrivateKey    PrivateKey;
> >> >        CryptoPP::ECIES< CryptoPP::ECP >::PublicKey     PublicKey;
> >> >        CryptoPP::AutoSeededRandomPool                  rng;
>
> >> > rng.Put((byte *)seed, strlen(seed));
>
> >> > PrivateKey.Initialize( rng, CryptoPP::ASN1::secp160k1() );
> >> >        PrivateKey.MakePublicKey( PublicKey );
>
> >> > CryptoPP::HexEncoder privFile(new CryptoPP::FileSink(privFilename));
> >> > PrivateKey.Save(privFile);
> >> > privFile.MessageEnd();
>
> >> > CryptoPP::HexEncoder pubFile(new CryptoPP::FileSink(pubFilename));
> >> > PublicKey.Save(pubFile);
> >> > pubFile.MessageEnd();- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


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