Package net.i2p.data
Class PrivateKey
java.lang.Object
net.i2p.data.SimpleDataStructure
net.i2p.data.PrivateKey
- All Implemented Interfaces:
Destroyable
,DataStructure
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 inherited from class net.i2p.data.SimpleDataStructure
_data
-
Constructor Summary
ConstructorDescriptionPrivateKey
(byte[] data) PrivateKey
(String base64Data) constructs from base64PrivateKey
(EncType type) PrivateKey
(EncType type, byte[] data) PrivateKey
(EncType type, byte[] data, PublicKey pubKey) -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
javax.security.auth.Destroyable interfaceboolean
Warning - this returns true for two different classes with the same size and same data, e.g.getType()
int
hashCode()
We assume the data has enough randomness in it, so use the last 4 bytes for speed.boolean
javax.security.auth.Destroyable interfaceint
length()
The legal length of the byte array in this data structuretoPublic()
Derives a new PublicKey object derived from the secret contents of this PrivateKey.toString()
Methods inherited from class net.i2p.data.SimpleDataStructure
calculateHash, fromBase64, fromByteArray, getData, read, readBytes, setData, toBase64, toByteArray, writeBytes
-
Field Details
-
KEYSIZE_BYTES
public static final int KEYSIZE_BYTES
-
-
Constructor Details
-
PrivateKey
public PrivateKey() -
PrivateKey
- Parameters:
type
- non-null- Since:
- 0.9.38
-
PrivateKey
public PrivateKey(byte[] data) -
PrivateKey
- Parameters:
type
- non-nulldata
- must be non-null- Since:
- 0.9.38
-
PrivateKey
- Parameters:
type
- non-nulldata
- must be non-nullpubKey
- corresponding pubKey to be cached- Since:
- 0.9.44
-
PrivateKey
constructs from base64- Parameters:
base64Data
- a string of base64 data (the output of .toBase64() called on a prior instance of PrivateKey- Throws:
DataFormatException
-
-
Method Details
-
length
public int length()Description copied from class:SimpleDataStructure
The legal length of the byte array in this data structure- Specified by:
length
in classSimpleDataStructure
-
getType
- Returns:
- non-null
- Since:
- 0.9.38
-
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:
destroy
in interfaceDestroyable
- Since:
- 0.9.40
-
isDestroyed
public boolean isDestroyed()javax.security.auth.Destroyable interface- Specified by:
isDestroyed
in interfaceDestroyable
- Since:
- 0.9.40
-
toString
- Overrides:
toString
in 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:
hashCode
in classSimpleDataStructure
-
equals
Description copied from class:SimpleDataStructure
Warning - 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:
equals
in classSimpleDataStructure
-