java.lang.Object
net.i2p.data.SimpleDataStructure
net.i2p.data.SigningPublicKey
- All Implemented Interfaces:
DataStructure
Cryptographic public key for digital signature verification in I2P.
SigningPublicKey provides signature verification capabilities:
- Default Algorithm: DSA-SHA1 (128 bytes)
- Modern Support: Variable length and type support since 0.9.8
- Key Structure: Contains only public exponent/coordinates
- Verification: Used to verify signatures and identities
Supported Algorithms:
- DSA-SHA1: Legacy algorithm, 128-byte keys
- ECDSA-P256: Modern algorithm, variable length keys
- EdDSA-Ed25519: Modern algorithm, 32-byte keys
- Future Types: Extensible design for new algorithms
Key Format:
- DSA: 128-byte public parameters (p, q, g, y)
- ECDSA: Variable length elliptic curve coordinates
- EdDSA: 32-byte compressed curve point
- Type Encoding: Algorithm type embedded in data
Usage:
- Signature Verification: Verify signatures from
SigningPrivateKey - Identity Verification: Part of
Destinationidentity - LeaseSet Verification: Verify LeaseSet authenticity
- Router Identity: Verify router signatures in NetDb
Performance Features:
- LRU Caching: Frequently used keys cached for efficiency
- Factory Methods: Static creation methods for cache access
- Efficient Storage: Optimized byte representation
- Fast Comparison: Optimized
equals(Object)and hashCode()
Security Considerations:
- Algorithm Choice: Prefer modern algorithms (Ed25519, ECDSA-P256)
- Key Validation: Verify key parameters before use
- Signature Verification: Always verify with correct algorithm
- Key Distribution: Safely transmit public keys
Blinding Support:
- Key Blinding: Support for blinded key variants
- Privacy: Enable anonymous service endpoints
- BlindData: Integration with
BlindDatafor blinding
Migration Path:
- Legacy: DSA-SHA1 for backward compatibility
- Modern: Ed25519 for better performance and security
- Transition: Mixed algorithm support during migration
Thread Safety:
- Immutable Data: Key data cannot be modified after creation
- Thread-Safe Cache: Static factory methods are thread-safe
- Safe Sharing: Instances can be safely shared between threads
Field Summary
Modifier and TypeFieldDescriptionprivate static final SDSCache<SigningPublicKey> Shared cache of parsed keys.private final SigTypeThe signature type of this key.private static final intNumber of leading data bytes that determine the 6-char b64 prefix intoString().private static final intKeys held in the shared cache.private static final SigTypeType assumed when a key names none.private static final byte[]Shared result for the no-padding case.static final intDefault key size in bytes (128 for DSA-SHA1).Fields inherited from class SimpleDataStructure
_dataConstructor Summary
ConstructorsConstructorDescriptionCreates a new SigningPublicKey with the default DSA-SHA1 type.SigningPublicKey(byte[] data) Creates a new SigningPublicKey from byte data with default type.SigningPublicKey(String base64Data) Signing public key from a string of base64 data.SigningPublicKey(SigType type) If null, type is unknown.SigningPublicKey(SigType type, byte[] data) If null, type is unknown.Method Summary
Modifier and TypeMethodDescriptionblind(SigningPrivateKey alpha) Only for SigType EdDSA_SHA512_Ed25519.static voidClears the public key cache.static SigningPublicKeycreate(byte[] data, int off) Pull from cache or return new.static SigningPublicKeycreate(InputStream in) Pull from cache or return new.booleanEqual if the keys are equal.byte[]getPadding(KeyCertificate kcert) Get the portion of this (type 0) SPK that is really padding based on the Key Cert type given, if any.getType()Gets the signature type of this public key.inthashCode()Hash code combining the type and data.intlength()Length of this public key.toString()Key summary for log messages.(package private) SigningPublicKeytoTypedKey(KeyCertificate kcert) Up-convert this from an untyped (type 0) SPK to a typed SPK based on the Key Cert given.(package private) voidWrite the data up to a max of 128 bytes.Methods inherited from class SimpleDataStructure
calculateHash, fromBase64, fromByteArray, getData, read, readBytes, setData, toBase64, toByteArray, writeBytesModifier and TypeMethodDescriptionSHA256 hash of the byte array, or null if data is null.voidfromBase64(String data) Data from the base64 string.voidfromByteArray(byte[] data) Does the same thing asSimpleDataStructure.setData(byte[])but null not allowed.byte[]getData()Data reference (not a copy).protected intread(InputStream in, byte[] target) Repeated reads until the buffer is full or IOException is thrown.voidreadBytes(InputStream in) Data read from the stream.voidsetData(byte[] data) The byte array data, or null.toBase64()Renders the structure into modified base 64 notation.byte[]Same thing as getData().voidwriteBytes(OutputStream out) Writes the data to the output stream.
Field Details
DEF_TYPE
Type assumed when a key names none.KEYSIZE_BYTES
public static final int KEYSIZE_BYTESDefault key size in bytes (128 for DSA-SHA1).CACHE_SIZE
EMPTY
private static final byte[] EMPTYShared result for the no-padding case. Zero-length arrays cannot be mutated, so a single instance may be handed to every caller.B64_PREFIX_BYTES
private static final int B64_PREFIX_BYTESNumber of leading data bytes that determine the 6-char b64 prefix intoString(). 6 b64 chars carry 36 bits, so 5 bytes are the minimum that reproduce them exactly.- See Also:
_cache
Shared cache of parsed keys._type
The signature type of this key.
Constructor Details
SigningPublicKey
public SigningPublicKey()Creates a new SigningPublicKey with the default DSA-SHA1 type.SigningPublicKey
If null, type is unknown.- Parameters:
type- if null, type is unknown
SigningPublicKey
public SigningPublicKey(byte[] data) Creates a new SigningPublicKey from byte data with default type.- Parameters:
data- the raw key material, which must match the length of the default DSA-SHA1 type or be null for a key whose data is set later
SigningPublicKey
If null, type is unknown.- Parameters:
type- if null, type is unknowndata- the key data
SigningPublicKey
Signing public key from a string of base64 data.- Parameters:
base64Data- a string of base64 data (the output of .toBase64() called on a prior instance of SigningPublicKey- Throws:
DataFormatException- if the base64 cannot be decoded or the decoded bytes are not a key of the length the signature type requires
Method Details
create
Pull from cache or return new. Deprecated - used only by deprecatedDestination.readBytes(data, off).- Parameters:
data- the buffer holding the encoded keyoff- the index in data at which the key starts- Returns:
- the cached or new key
create
Pull from cache or return new.- Parameters:
in- the stream to read the encoded key from- Returns:
- the cached or new key
- Throws:
IOException- if the key cannot be read from the stream
length
public int length()Length of this public key.- Specified by:
lengthin classSimpleDataStructure- Returns:
- the key length in bytes: from the signature type if known, otherwise the data length, or 128 if no data
getType
toTypedKey
Up-convert this from an untyped (type 0) SPK to a typed SPK based on the Key Cert given. The type of the returned key will be null if the kcert sigtype is null.- Parameters:
kcert- the key certificate- Returns:
- the typed signing public key
- Throws:
IllegalArgumentException- if this is already typed to a different type
getPadding
Get the portion of this (type 0) SPK that is really padding based on the Key Cert type given, if any.- Parameters:
kcert- the key certificate- Returns:
- the leading padding, or a shared empty array if there is no padding or the type is unknown
- Throws:
IllegalStateException- if this is already typed to a different type
writeTruncatedBytes
Write the data up to a max of 128 bytes. If longer, the rest will be written in the KeyCertificate.- Parameters:
out- the stream the truncated key bytes are written to- Throws:
DataFormatException- if the key holds no data at allIOException- if the stream rejects the key bytes
blind
Only for SigType EdDSA_SHA512_Ed25519.- Parameters:
alpha- the secret data- Returns:
- the blinded public key
- Throws:
UnsupportedOperationException- for an unsupported group representation
toString
Key summary for log messages.- Overrides:
toStringin classSimpleDataStructure
clearCache
public static void clearCache()Clears the public key cache.hashCode
public int hashCode()Hash code combining the type and data.- Overrides:
hashCodein classSimpleDataStructure- Returns:
- the hash code
equals
Equal if the keys are equal.- Overrides:
equalsin classSimpleDataStructure- Parameters:
obj- the object to compare- Returns:
- true if the data arrays are equal