You're close, you just generated the public key into a SecByteBlock now you just need to call BytePtr() on this block and maybe somehow retrieve it's size and send this bytes to the party you're adressing. When loading from a file you would just store the curve (-> Curve-Size?), the key size (Privatekeylength & publickeylength) and load the key-bytes from the file. AND I'd really doubt that it's clever to store the public and private key in a file. Normally you would just send the public key via network and be happy and generate a new pair for each execution.
BR JPM Am Dienstag, 10. Juni 2014 13:03:49 UTC+2 schrieb Damias: > > I do not find any function to load the public key. I've tried to use > BERDecode on DH Domain > http://www.cryptopp.com/docs/ref/class_d_h___domain.html but without > success. I've tried too declaring a CryptoPP::ECIES< CryptoPP::ECP > >::PublicKey and using .Load, but nothing. I've managed to pass from > SecByteBlock to Byte but now i would need to load a public key in .der > format on this. > > Here's is the code I have at the moment. > > int main( int, char** ) { > > OID CURVE = secp256k1(); > AutoSeededX917RNG<AES> rng; > > /* A */ > ECDH < ECP >::Domain dhA( CURVE ); > > byte privA[dhA.PrivateKeyLength()]; > byte pubA[dhA.PublicKeyLength()]; > > dhA.GenerateKeyPair(rng, privA, pubA); > > byte sharedA[dhA.AgreedValueLength()]; > > /* B */ > ECDH < ECP >::Domain dhB( CURVE ); > > byte privB[dhB.PrivateKeyLength()]; > byte pubB[dhB.PublicKeyLength()]; > > dhB.GenerateKeyPair(rng, privB, pubB); > > byte sharedB[dhB.AgreedValueLength()]; > > /* AGREEMENT */ > dhA.Agree (sharedA, privA, pubB); > dhB.Agree (sharedB, privB, pubA); > > if ((dhA.AgreedValueLength() != dhB.AgreedValueLength()) || (memcmp > (sharedB, sharedA, dhA.AgreedValueLength()) != 0)) { > cout << "Something wrong" << endl; > } > else { > cout << "Agreed to shared secret" << endl; > } > > return 0; > } > > If I use: > > CryptoPP::ECIES< CryptoPP::ECP >::PublicKey pubA; > CryptoPP::ECIES< CryptoPP::ECP >::PrivateKey privA; > > string namepub = "ec-pubkey.der"; > string namepriv = "ec-privkey.der"; > pubA.Load(FileSource( namepub.c_str(), true, NULL, true /*binary*/ > ).Ref()); > privA.Load(FileSource( namepriv.c_str(), true, NULL, true /*binary*/ > ).Ref()); > > Instead of: > > byte privA[dhA.PrivateKeyLength()]; > byte pubA[dhA.PublicKeyLength()]; > > dhA.GenerateKeyPair(rng, privA, pubA); > > byte sharedA[dhA.AgreedValueLength()]; > > The code compiles but when I execute it: > terminate called after throwing an instance of 'CryptoPP::BERDecodeErr' > what(): BER decode error > > -- -- 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. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
