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
> length string?
>
>
>
> 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();
>
>
> > 



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