org.bitcoin.x6763.crypto.ecdsa
Class PublicKey

java.lang.Object
  extended by org.bitcoin.x6763.crypto.ecdsa.PublicKey
All Implemented Interfaces:
java.io.Serializable, java.security.Key, java.security.PublicKey, ECKey, ECPublicKey, Secp256k1

public class PublicKey
extends java.lang.Object
implements Secp256k1, ECPublicKey

An elliptic curve public key, generated for the secp256k1 elliptic curve.

Author:
x6763
See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Fields inherited from interface org.bitcoin.x6763.crypto.ecdsa.Secp256k1
a, algorithm, b, bigX, bigY, curve, G, h, n, p, parameters, x, y
 
Constructor Summary
PublicKey(byte[] publicKeyBytes)
          Converts a 64 or 65-byte byte-array to a public key.
PublicKey(ECPoint W)
          Creates an elliptic curve public key object from an ECPoint
PublicKey(PrivateKey privateKey)
          Derives a public key from a private key.
 
Method Summary
 java.lang.String getAlgorithm()
          Returns the algorithm name, "ECDSA".
 byte[] getEncoded()
          Encodes the public key into the same format used by Bitcoin.
 java.lang.String getFormat()
           
 ECDomainParameters getParams()
          Returns the elliptic curve domain parameters for the secp256k1 curve.
 ECPoint getW()
          Returns the public key coordinates as an ECPoint object
 byte[] serialize()
          Serializes the public key into a 64 byte array in the format of: [256-bit x-coordinate] [256-bit y-coordinate]
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

PublicKey

public PublicKey(ECPoint W)
Creates an elliptic curve public key object from an ECPoint

Parameters:
W -

PublicKey

public PublicKey(PrivateKey privateKey)
Derives a public key from a private key.

Parameters:
privateKey - a private key object that the public key will be derived from

PublicKey

public PublicKey(byte[] publicKeyBytes)
          throws java.security.InvalidKeyException
Converts a 64 or 65-byte byte-array to a public key. The byte-array is expected to contain two 256-bit numbers, the x and y coordinates of the elliptic curve public key. This constructor also supports a 65-byte byte-array containing at index 0 the byte 0x04, providing direct support for Bitcoin's public key format.

Parameters:
publicKeyBytes - a byte-array containing the x and y coordinates of a public key
Throws:
java.security.InvalidKeyException
Method Detail

getParams

public ECDomainParameters getParams()
Returns the elliptic curve domain parameters for the secp256k1 curve.

Specified by:
getParams in interface ECKey
Returns:
the secp256k1 elliptic curve domain parameters

getAlgorithm

public java.lang.String getAlgorithm()
Returns the algorithm name, "ECDSA".

Specified by:
getAlgorithm in interface java.security.Key
Returns:
the algorithm name, "EDCSA"

getEncoded

public byte[] getEncoded()
Encodes the public key into the same format used by Bitcoin. Format: 0x04 [256-bit x-coordinate] [256-bit y-coordinate]

Specified by:
getEncoded in interface java.security.Key
Returns:
the array of bytes for the Bitcoin compatible encoded public key

getFormat

public java.lang.String getFormat()
Specified by:
getFormat in interface java.security.Key
Returns:
null

getW

public ECPoint getW()
Returns the public key coordinates as an ECPoint object

Specified by:
getW in interface ECPublicKey
Returns:
the public key point W

serialize

public byte[] serialize()
Serializes the public key into a 64 byte array in the format of: [256-bit x-coordinate] [256-bit y-coordinate]

Returns:
the array of bytes of the two 256-bit public key coordinates