net.i2p.data
Class PrivateKey

java.lang.Object
  extended by net.i2p.data.DataStructureImpl
      extended by net.i2p.data.SimpleDataStructure
          extended by net.i2p.data.PrivateKey
All Implemented Interfaces:
DataStructure

public class PrivateKey
extends SimpleDataStructure

Defines the PrivateKey as defined by the I2P data structure spec. A private key is 256byte Integer. The private key represents only the exponent, not the primes, which are constant and defined in the crypto spec. Note that we use short exponents, so all but the last 28.25 bytes are zero. See http://www.i2p2.i2p/how_cryptography for details.

Author:
jrandom

Field Summary
static int KEYSIZE_BYTES
           
 
Fields inherited from class net.i2p.data.SimpleDataStructure
_data, _length
 
Constructor Summary
PrivateKey()
           
PrivateKey(byte[] data)
           
PrivateKey(String base64Data)
          constructs from base64
 
Method Summary
 boolean equals(Object obj)
           
 int hashCode()
          We assume the data has enough randomness in it, so use the last 4 bytes for speed.
 int length()
          The legal length of the byte array in this data structure
 PublicKey toPublic()
          derives a new PublicKey object derived from the secret contents of this PrivateKey
 
Methods inherited from class net.i2p.data.SimpleDataStructure
calculateHash, fromBase64, fromByteArray, getData, readBytes, setData, toBase64, toByteArray, toString, writeBytes
 
Methods inherited from class net.i2p.data.DataStructureImpl
read
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

KEYSIZE_BYTES

public static final int KEYSIZE_BYTES
See Also:
Constant Field Values
Constructor Detail

PrivateKey

public PrivateKey()

PrivateKey

public PrivateKey(byte[] data)

PrivateKey

public PrivateKey(String base64Data)
           throws DataFormatException
constructs from base64

Parameters:
base64Data - a string of base64 data (the output of .toBase64() called on a prior instance of PrivateKey
Throws:
DataFormatException
Method Detail

length

public int length()
Description copied from class: SimpleDataStructure
The legal length of the byte array in this data structure

Specified by:
length in class SimpleDataStructure

toPublic

public PublicKey toPublic()
derives a new PublicKey object derived from the secret contents of this PrivateKey

Returns:
a PublicKey object

hashCode

public int hashCode()
We assume the data has enough randomness in it, so use the last 4 bytes for speed. Overridden since we use short exponents, so the first 227 bytes are all zero. Not that we are storing PrivateKeys in any Sets or Maps anywhere.

Overrides:
hashCode in class SimpleDataStructure

equals

public boolean equals(Object obj)
Overrides:
equals in class SimpleDataStructure