net.i2p.data

## Class SigningPrivateKey

- java.lang.Object
- - net.i2p.data.SimpleDataStructure
  - - net.i2p.data.SigningPrivateKey

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

      public class SigningPrivateKey
      extends 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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `KEYSIZE_BYTES`

    - ### Fields inherited from class net.i2p.data.SimpleDataStructure

      `_data`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SigningPrivateKey()`
    `SigningPrivateKey(byte[] data)`
    `SigningPrivateKey(SigType type)`
    `SigningPrivateKey(SigType type, byte[] data)`
    `SigningPrivateKey(String base64Data)` constructs from base64

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `SigningPrivateKey` | `blind(SigningPrivateKey alpha)` Only for SigType EdDSA_SHA512_Ed25519
    `void` | `destroy()` javax.security.auth.Destroyable interface
    `boolean` | `equals(Object obj)` Warning - this returns true for two different classes with the same size and same data, e.g.
    `SigType` | `getType()` Gets the signature type of this private key.
    `int` | `hashCode()` We assume the data has enough randomness in it, so use the first 4 bytes for speed.
    `boolean` | `isDestroyed()` javax.security.auth.Destroyable interface
    `boolean` | `isOffline()` Constant time
    `int` | `length()` The legal length of the byte array in this data structure
    `SigningPublicKey` | `toPublic()` Converts this signing private key to its public equivalent.
    `String` | `toString()`

    - ### Methods inherited from class net.i2p.data.SimpleDataStructure

      `calculateHash, fromBase64, fromByteArray, getData, read, readBytes, setData, toBase64, toByteArray, writeBytes`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### KEYSIZE_BYTES

          public static final int KEYSIZE_BYTES

  - ### Constructor Detail

    - #### SigningPrivateKey

          public SigningPrivateKey()

    - #### SigningPrivateKey

          public SigningPrivateKey(byte[] data)

    - #### SigningPrivateKey

          public SigningPrivateKey(SigType type)

    - #### SigningPrivateKey

          public SigningPrivateKey(SigType type,
                                   byte[] data)

    - #### SigningPrivateKey

          public SigningPrivateKey(String base64Data)
                            throws DataFormatException

      constructs from base64
      Parameters:
        `base64Data` - a string of base64 data (the output of .toBase64() called on a prior instance of SigningPrivateKey
      Throws:
        `DataFormatException`

  - ### Method Detail

    - #### blind

          public SigningPrivateKey blind(SigningPrivateKey alpha)

      Only for SigType EdDSA_SHA512_Ed25519
      Parameters:
        `alpha` - the secret data
      Throws:
        `UnsupportedOperationException` - unless supported

    - #### destroy

          public void destroy()

      javax.security.auth.Destroyable interface
      Specified by:
        `destroy` in interface `Destroyable`

    - #### equals

          public boolean equals(Object obj)

      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 class `SimpleDataStructure`

    - #### getType

          public SigType getType()

      Gets the signature type of this private key.

    - #### 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 class `SimpleDataStructure`

    - #### isDestroyed

          public boolean isDestroyed()

      javax.security.auth.Destroyable interface
      Specified by:
        `isDestroyed` in interface `Destroyable`

    - #### isOffline

          public boolean isOffline()

      Constant time
      Returns:
        true if all zeros

    - #### length

          public int length()

      Description copied from class: `SimpleDataStructure`
      The legal length of the byte array in this data structure
      Specified by:
        `length` in class `SimpleDataStructure`

    - #### 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

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `SimpleDataStructure`