All Implemented Interfaces:
Destroyable, DataStructure
Direct Known Subclasses:
RSASigningPrivateCrtKey

public class SigningPrivateKeyextends SimpleDataStructure implements Destroyable
Cryptographic private key for digital signature generation in I2P.

SigningPrivateKey provides signature generation capabilities:

  • Default Algorithm: DSA-SHA1 (20 bytes)
  • Modern Support: Variable length and type support since 0.9.8
  • Key Structure: Contains only private exponent/coordinates
  • Security: Implements Destroyable for secure cleanup

Supported Algorithms:

  • DSA-SHA1: Legacy algorithm, 20-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: 20-byte private exponent (x)
  • ECDSA: Variable length private scalar
  • EdDSA: 32-byte private seed
  • Type Encoding: Algorithm type embedded in data

Usage:

  • Signature Generation: Sign data with corresponding SigningPublicKey
  • Identity Creation: Part of Destination identity
  • LeaseSet Signing: Sign LeaseSet for network publication
  • Router Identity: Sign router information for NetDb

Security Considerations:

  • Confidentiality: Private signing keys must never be exposed
  • Secure Destruction: Call destroy() when no longer needed
  • Memory Protection: Zeroize memory after use
  • Algorithm Choice: Prefer modern algorithms (Ed25519, ECDSA-P256)

Blinding Support:

  • Key Blinding: Support for generating blinded key variants
  • Privacy: Enable anonymous service endpoints
  • BlindData: Integration with BlindData for blinding operations

Performance Features:

  • Efficient Storage: Optimized byte representation
  • Factory Methods: Static creation methods for consistency
  • Fast Operations: Optimized for high-frequency signing

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
  • Safe Destruction: Thread-safe key zeroization
  • Exclusive Use: Each instance should be used by only one thread
  • Field Details

    • DEF_TYPE

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

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

      private final SigType _type
      The algorithm this key signs with.
  • Constructor Details

    • SigningPrivateKey

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

      public SigningPrivateKey(SigType type)
      Creates an empty signing private key for the given signature algorithm.
      Parameters:
      type - the signature algorithm this key is used with, which fixes the key length
    • SigningPrivateKey

      public SigningPrivateKey(byte[] data)
      Creates a new SigningPrivateKey from byte data with default type.
      Parameters:
      data - the raw private key bytes, which must match the default type's key length
    • SigningPrivateKey

      public SigningPrivateKey(SigType type, byte[] data)
      Creates a signing private key for the given algorithm from raw key bytes.
      Parameters:
      type - the signature algorithm, which fixes the key length and signing algorithm
      data - the raw private key bytes, whose length must match the type's privkey length
    • SigningPrivateKey

      public SigningPrivateKey(String base64Data) throws DataFormatException
      Signing private key from a string of base64 data.
      Parameters:
      base64Data - a string of base64 data (the output of .toBase64() called on a prior instance of SigningPrivateKey
      Throws:
      DataFormatException - if the string is not valid base64, or does not decode to the key length required by the default signature type
  • Method Details

    • length

      public int length()
      Key length in bytes, determined by the signature type.
      Specified by:
      length in class SimpleDataStructure
      Returns:
      the legal length of the byte array
    • getType

      public SigType getType()
      Signature type of this private key.
      Returns:
      the SigType this key was created with
    • toPublic

      public SigningPublicKey toPublic()
      Converts this signing private key to its public equivalent. As of 0.9.16, supports all key types.
      Returns:
      a SigningPublicKey object derived from this private key
      Throws:
      IllegalArgumentException - on bad key or unknown or unsupported type
    • blind

      public SigningPrivateKey blind(SigningPrivateKey alpha)
      Only for SigType EdDSA_SHA512_Ed25519.
      Parameters:
      alpha - the secret data
      Returns:
      the blinded private key
      Throws:
      UnsupportedOperationException - never thrown; see IllegalArgumentException
    • isOffline

      public boolean isOffline()
      Constant time.
      Returns:
      true if all zeros
    • destroy

      public void destroy()
      Destroy this key and clear its data, per the javax.security.auth.Destroyable interface.
      Specified by:
      destroy in interface Destroyable
    • isDestroyed

      public boolean isDestroyed()
      Whether this key has been destroyed.
      Specified by:
      isDestroyed in interface Destroyable
      Returns:
      true if destroy() has cleared the key data, or it was never set
    • toString

      public String toString()
      Key summary for log messages.
      Overrides:
      toString in class SimpleDataStructure
    • 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