Package net.i2p.data
Class PublicKey
java.lang.Object
net.i2p.data.SimpleDataStructure
net.i2p.data.PublicKey
- All Implemented Interfaces:
DataStructure
- Direct Known Subclasses:
NextSessionKey
public class PublicKey extends SimpleDataStructure
Defines the PublicKey as defined by the I2P data structure spec.
A public key is 256byte Integer. The public 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.
Note: Support for keys longer than 256 bytes unimplemented.
See EncType.
- Author:
- jrandom
-
Field Summary
Fields Modifier and Type Field Description static int
KEYSIZE_BYTES
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description static void
clearCache()
static PublicKey
create(byte[] data, int off)
Pull from cache or return new.static PublicKey
create(InputStream in)
Pull from cache or return new.boolean
equals(Object obj)
Warning - this returns true for two different classes with the same size and same data, e.g.byte[]
getPadding(KeyCertificate kcert)
Get the portion of this (type 0) PK that is really padding based on the Key Cert type given, if anyEncType
getType()
int
getUnknownTypeCode()
Only valid if getType() returns nullint
hashCode()
We assume the data has enough randomness in it, so use the first 4 bytes for speed.int
length()
The legal length of the byte array in this data structureString
toString()
PublicKey
toTypedKey(KeyCertificate kcert)
Up-convert this from an untyped (type 0) PK to a typed PK based on the Key Cert given.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
-
PublicKey
public PublicKey() -
PublicKey
- Parameters:
type
- if null, type is unknown- Since:
- 0.9.38
-
PublicKey
public PublicKey(byte[] data)- Parameters:
data
- must be non-null
-
PublicKey
- Parameters:
type
- if null, type is unknowndata
- must be non-null- Since:
- 0.9.38
-
PublicKey
public PublicKey(int typeCode, byte[] data)Unknown type only.- Parameters:
typeCode
- must not match a known type. 1-255data
- must be non-null- Since:
- 0.9.38
-
PublicKey
Constructs from base64. ElGamal only.- Parameters:
base64Data
- a string of base64 data (the output of .toBase64() called on a prior instance of PublicKey- Throws:
DataFormatException
-
-
Method Details
-
create
Pull from cache or return new. ELGAMAL_2048 only! Deprecated - used only by deprecated Destination.readBytes(data, off)- Throws:
ArrayIndexOutOfBoundsException
- if not enough bytes, FIXME should throw DataFormatException- Since:
- 0.8.3
-
create
Pull from cache or return new. ELGAMAL_2048 only!- Throws:
IOException
- Since:
- 0.8.3
-
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:
- null if unknown
- Since:
- 0.9.38
-
getUnknownTypeCode
public int getUnknownTypeCode()Only valid if getType() returns null- Since:
- 0.9.38
-
toTypedKey
Up-convert this from an untyped (type 0) PK to a typed PK based on the Key Cert given. The type of the returned key will be null if the kcert sigtype is null.- Throws:
IllegalArgumentException
- if this is already typed to a different type- Since:
- 0.9.42
-
getPadding
Get the portion of this (type 0) PK that is really padding based on the Key Cert type given, if any- Returns:
- trailing padding length > 0 or null if no padding or type is unknown
- Throws:
IllegalArgumentException
- if this is already typed to a different type- Since:
- 0.9.42
-
clearCache
public static void clearCache()- Since:
- 0.9.17
-
toString
- Overrides:
toString
in classSimpleDataStructure
- Since:
- 0.9.38
-
hashCode
public int hashCode()Description copied from class:SimpleDataStructure
We assume the data has enough randomness in it, so use the first 4 bytes for speed. If this is not the case, override in the extending class.- Overrides:
hashCode
in classSimpleDataStructure
- Since:
- 0.9.42
-
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
- Since:
- 0.9.42
-