I save and load the compressed version of EC keys in BaseEncoded form:

void Security::SavePublicKeyinFile (string pub){ //pub--> name of the file 
to be saved

Base64Encoder pubkeysink(new FileSink(pub.c_str()));
publicKey.GetGroupParameters().GetCurve().EncodePoint(pubkeysink,publicKey.GetPublicElement(),true);
pubkeysink.MessageEnd(); // Need to flush Base64Encoders buffer
}


void Security::LoadPublicKeyfromFile (ECDSA<ECP, SHA1>::PublicKey 
&SubjectPublicKey, char* pub){ //pub--> name of the file to be loaded

FileSource pubSrc(pub, true, new Base64Decoder);
ECP::Point pp;
SubjectPublicKey.AccessGroupParameters().Initialize(CryptoPP::ASN1::secp224r1());
SubjectPublicKey.GetGroupParameters().GetCurve().DecodePoint(pp,pubSrc,SubjectPublicKey.GetGroupParameters().GetCurve().EncodedPointSize(true));
SubjectPublicKey.SetPublicElement(pp);
}

/Amin


On Monday, September 19, 2011 12:19:53 AM UTC+2, Niij wrote:
>
> Hi, 
>
> I'm in the same situation as you but with EC scheme, I used Harry's 
> code (http://groups.google.com/group/cryptopp-users/browse_thread/ 
> thread/e58e46f0e8558f2b/022e858d15529859?lnk=gst&q=How+to+save+public 
> +key+and+private+key+for+#022e858d15529859<http://groups.google.com/group/cryptopp-users/browse_thread/thread/e58e46f0e8558f2b/022e858d15529859?lnk=gst&q=How+to+save+public+key+and+private+key+for+#022e858d15529859>)
>  
>
>  to get the private and public key written on files and now I 'd like 
> to Load the public key from the public.key file using the Load() 
> method from PublicKey class 
>
> Here is the portion of my code  : 
>         CryptoPP::ECIES < ECC_ALGORITHM >::Encryptor Encryptor 
> (publicKey); 
>
> // Public Key Loading 
>
> std::ifstream file2("Public.key", std::ios::in); 
>          string public_k; 
>          if(file2) 
>            { 
>                 getline(file2, public_k);  //  put the first line on 
> "public_k" 
>                 cout <<  "the public key " << public_k << endl ;  // 
> display the line 
>                 file2.close(); 
>         } 
>         else 
>         cerr << "impossible to open the file!" << endl; 
>
> publicKey.Load(public_k); 
>
> ------------- 
>
> After compiling I got the following error : 
>  error: no matching function for call to 
> ‘CryptoPP::DL_PublicKey_EC<CryptoPP::ECP>::Load(std::string&)’ 
> /usr/include/cryptopp/asn.h:240: note: candidates are: void 
> CryptoPP::ASN1CryptoMaterial<BASE>::Load(CryptoPP::BufferedTransformation&) 
>
> [with BASE = CryptoPP::PublicKey] 
>
> The problem seems to be the choice of the parameter type for Load() , 
> which should  be BufferedTransformation&. How can I convert from 
> string to this type then ? 
>
> thanks for help. 
>
>
>
>
>
>
>

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