Package net.i2p.data
Class PrivateKey
- java.lang.Object
-
- net.i2p.data.SimpleDataStructure
-
- net.i2p.data.PrivateKey
-
- All Implemented Interfaces:
Destroyable,DataStructure
public class PrivateKey extends SimpleDataStructure implements Destroyable
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
-
-
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)PrivateKey(EncType type, byte[] data, PublicKey pubKey)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()javax.security.auth.Destroyable interfacebooleanequals(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.booleanisDestroyed()javax.security.auth.Destroyable interfaceintlength()The legal length of the byte array in this data structurePublicKeytoPublic()Derives a new PublicKey object derived from the secret contents of this PrivateKey.StringtoString()-
Methods inherited from class net.i2p.data.SimpleDataStructure
calculateHash, fromBase64, fromByteArray, getData, read, readBytes, setData, toBase64, toByteArray, writeBytes
-
-
-
-
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(EncType type, byte[] data, PublicKey pubKey)
- Parameters:
type- non-nulldata- must be non-nullpubKey- corresponding pubKey to be cached- Since:
- 0.9.44
-
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. As of 0.9.44, the PublicKey is cached.- Returns:
- a PublicKey object
- Throws:
IllegalArgumentException- on bad key
-
destroy
public void destroy()
javax.security.auth.Destroyable interface- Specified by:
destroyin interfaceDestroyable- Since:
- 0.9.40
-
isDestroyed
public boolean isDestroyed()
javax.security.auth.Destroyable interface- Specified by:
isDestroyedin interfaceDestroyable- Since:
- 0.9.40
-
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
-
-