Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: FabioCarpi on January 05, 2015, 11:49:26 PM



Title: compressed pubkey version
Post by: FabioCarpi on January 05, 2015, 11:49:26 PM
How to know when to use version 02 or 03 in a compressed pubkey?

let me explain:
in the bitcoin qt, i type the command dumpprivkey in my address 1Cue...
he gave me the key Kw...
but making some tests, with version 02, i got the address 1Nra...
and with the version 03, the 1Cue...


Title: Re: compressed pubkey version
Post by: amaclin on January 05, 2015, 11:54:54 PM
How to know when to use version 02 or 03 in a compressed pubkey?

Code:
const QByteArray MyKey32::getPublicKeyClassic ( ) const
{
  quint8 buf [65];
  getPublicKey ( buf );
//buf [0] = 0x04;
  return QByteArray ( (const char*)buf, 65 );
}
//--------------------------------------------------------------
const QByteArray MyKey32::getPublicKeyCompressed ( ) const
{
  quint8 buf [65];
  getPublicKey ( buf );
  buf [0] = 0x02 + ( buf [64] & 1 );
  return QByteArray ( (const char*)buf, 33 );
}


Title: Re: compressed pubkey version
Post by: FabioCarpi on January 05, 2015, 11:57:18 PM
sry amaclin, i post some info...


Title: Re: compressed pubkey version
Post by: amaclin on January 06, 2015, 12:04:46 AM
sry amaclin, i post some info...

Public key is a pair [x,y]
if 'y' is even - use 0x02
if 'y' is odd - use 0x03


Code:
buf [0] = 0x02 + ( buf [64] & 1 );