> I'm trying to retrieve a public key, given x and y with the following code: > > //x and y came from a webservice > std::string x = > "40BA49FCBA45C7EEB2261B1BE0EBC7C14D6484B9EF8A23B060EBE67F97252BBC"; > std::string y = > "00987BA49DF364A0C9926F2B6DE1BAF46068A13A2C5C9812B2F3451F48B75719EE"; > std::string pt = x + y; > CryptoPP::HexDecoder decoder; > decoder.Put((byte*)pt.data(), pt.size()); > decoder.MessageEnd(); > > CryptoPP::ECP::Point q; > size_t len = decoder.MaxRetrievable(); > > q.identity = false; > q.x.Decode(decoder, len / 2); > q.y.Decode(decoder, len / 2); //Wrong value > > CryptoPP::ECDSA<CryptoPP::ECP, CryptoPP::SHA256>::PublicKey publicKey; > publicKey.Initialize(CryptoPP::ASN1::brainpoolP256r1(), q); > > After Initializing the public key, I try to validate it: > > CryptoPP::ECDSA<CryptoPP::ECP, CryptoPP::SHA256>::Verifier > verifier(publicKey); > > CryptoPP::AutoSeededRandomPool prng; > bool result = publicKey.Validate(prng, 3); > > result is always false and I tried to get the int-values of x and y with the > following: > > const CryptoPP::ECP::Point& qq = publicKey.GetPublicElement(); > std::ostringstream cou; > cou << "Q.x: " << qq.x; > cou << "Q.y: " << qq.y; > OutputDebugStringA(cou.str().c_str()); > > While x seems to be okay, y is not. And I don't know what to do... Is there > anybody with a similar problem and a possible solution?
Drop the leading 00 on the y-coordinate. The leading 00 is needed for ASN.1 encoding. Crypto++ uses a simple concatenation (x || y). Not that x and y need to be the size of a field element, which is 32-bytes. So (x || y) should be 64-bytes in total. Also, are you sure the curve is brainpoolP256r1? ECDSA is usually over secp256r1. Jeff -- 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 cryptopp-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8nQvze5Opi40L0eye3HdeCyWwHydUUERvQ3YJVYJ8rYKg%40mail.gmail.com.