Retrieving public key from x and y
Benjamin Schäfer <[email protected]>
| Newsgroups | gmane.comp.encryption.cryptopp |
|---|---|
| Message-ID | <[email protected]> |
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 [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/cryptopp-users/0e460928-1dde-4d4e-8326-934e0427ea46n%40googlegroups.com.