Package net.i2p.data
Class PrivateKey
- java.lang.Object
-
- net.i2p.data.DataStructureImpl
-
- net.i2p.data.SimpleDataStructure
-
- net.i2p.data.PrivateKey
-
- All Implemented Interfaces:
Serializable,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. As of release 0.9.38, keys of arbitrary length and type are supported. See EncType.- Author:
- jrandom
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intKEYSIZE_BYTES-
Fields inherited from class net.i2p.data.SimpleDataStructure
_data
-
-
Constructor Summary
Constructors Constructor Description PrivateKey()PrivateKey(byte[] data)PrivateKey(String base64Data)constructs from base64PrivateKey(EncType type)PrivateKey(EncType type, byte[] data)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Warning - this returns true for two different classes with the same size and same data, e.g.EncTypegetType()inthashCode()We assume the data has enough randomness in it, so use the last 4 bytes for speed.intlength()The legal length of the byte array in this data structurePublicKeytoPublic()derives a new PublicKey object derived from the secret contents of this PrivateKeyStringtoString()-
Methods inherited from class net.i2p.data.SimpleDataStructure
calculateHash, fromBase64, fromByteArray, getData, readBytes, setData, toBase64, toByteArray, writeBytes
-
Methods inherited from class net.i2p.data.DataStructureImpl
read
-
-
-
-
Constructor Detail
-
PrivateKey
public PrivateKey()
-
PrivateKey
public PrivateKey(EncType type)
- Parameters:
type- non-null- Since:
- 0.9.38
-
PrivateKey
public PrivateKey(byte[] data)
-
PrivateKey
public PrivateKey(EncType type, byte[] data)
- Parameters:
type- non-nulldata- must be non-null- Since:
- 0.9.38
-
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:SimpleDataStructureThe legal length of the byte array in this data structure- Specified by:
lengthin classSimpleDataStructure
-
getType
public EncType getType()
- Returns:
- non-null
- Since:
- 0.9.38
-
toPublic
public PublicKey toPublic()
derives a new PublicKey object derived from the secret contents of this PrivateKey- Returns:
- a PublicKey object
- Throws:
IllegalArgumentException- on bad key
-
toString
public String toString()
- Overrides:
toStringin classSimpleDataStructure- Since:
- 0.9.38
-
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.- Overrides:
hashCodein classSimpleDataStructure
-
equals
public boolean equals(Object obj)
Description copied from class:SimpleDataStructureWarning - this returns true for two different classes with the same size and same data, e.g. SessionKey and SessionTag, but you wouldn't put them in the same Set, would you?- Overrides:
equalsin classSimpleDataStructure
-
-