Ok, I was able to find out, why I get a wrong y coordinate (leading zeros 
in Hex-String brings up this crap). Validation seems to be okay. 

But my problem afterward (which I didn't mention to this point, because I 
thought it will solve itself when I have a correct y-coordinate) is, that 
if I try to save this public key as PEM, I only get 

-----BEGIN PUBLIC KEY-----
MFowMFow-----END PUBLIC KEY-----

as result. This was also my result with wrong y and failed validation. 



Benjamin Schäfer schrieb am Dienstag, 14. September 2021 um 18:04:26 UTC+2:

> Hi there,
>
> 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?
>
>
> Best regards
>

-- 
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/f193b607-7e7a-4fed-a3e5-5768642d5314n%40googlegroups.com.

Reply via email to