All Implemented Interfaces:
DataStructure

public class SigningPublicKeyextends SimpleDataStructure
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 Destination identity
  • 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 BlindData for 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 Details

    • DEF_TYPE

      private static final SigType DEF_TYPE
      Type assumed when a key names none.
    • KEYSIZE_BYTES

      public static final int KEYSIZE_BYTES
      Default key size in bytes (128 for DSA-SHA1).
    • CACHE_SIZE

      private static final int CACHE_SIZE
      Keys held in the shared cache.
      See Also:
    • EMPTY

      private static final byte[] EMPTY
      Shared 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_BYTES
      Number of leading data bytes that determine the 6-char b64 prefix in toString(). 6 b64 chars carry 36 bits, so 5 bytes are the minimum that reproduce them exactly.
      See Also:
    • _cache

      private static final SDSCache<SigningPublicKey> _cache
      Shared cache of parsed keys.
    • _type

      private final SigType _type
      The signature type of this key.
  • Constructor Details

    • SigningPublicKey

      public SigningPublicKey()
      Creates a new SigningPublicKey with the default DSA-SHA1 type.
    • SigningPublicKey

      public SigningPublicKey(SigType type)
      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

      public SigningPublicKey(SigType type, byte[] data)
      If null, type is unknown.
      Parameters:
      type - if null, type is unknown
      data - the key data
    • SigningPublicKey

      public SigningPublicKey(String base64Data) throws DataFormatException
      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

      public static SigningPublicKey create(byte[] data, int off)
      Pull from cache or return new. Deprecated - used only by deprecated Destination.readBytes(data, off).
      Parameters:
      data - the buffer holding the encoded key
      off - the index in data at which the key starts
      Returns:
      the cached or new key
    • create

      public static SigningPublicKey create(InputStream in) throws IOException
      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:
      length in class SimpleDataStructure
      Returns:
      the key length in bytes: from the signature type if known, otherwise the data length, or 128 if no data
    • getType

      public SigType getType()
      Gets the signature type of this public key.
      Returns:
      null if unknown
    • toTypedKey

      SigningPublicKey toTypedKey(KeyCertificate kcert)
      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

      public 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.
      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

      void writeTruncatedBytes(OutputStream out) throws DataFormatException, IOException
      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 all
      IOException - if the stream rejects the key bytes
    • blind

      public SigningPublicKey blind(SigningPrivateKey alpha)
      Only for SigType EdDSA_SHA512_Ed25519.
      Parameters:
      alpha - the secret data
      Returns:
      the blinded public key
      Throws:
      UnsupportedOperationException - for an unsupported group representation
    • toString

      public String toString()
      Key summary for log messages.
      Overrides:
      toString in class SimpleDataStructure
    • clearCache

      public static void clearCache()
      Clears the public key cache.
    • hashCode

      public int hashCode()
      Hash code combining the type and data.
      Overrides:
      hashCode in class SimpleDataStructure
      Returns:
      the hash code
    • equals

      public boolean equals(Object obj)
      Equal if the keys are equal.
      Overrides:
      equals in class SimpleDataStructure
      Parameters:
      obj - the object to compare
      Returns:
      true if the data arrays are equal