net.i2p.crypto.eddsa

## Class EdDSAPrivateKey

- java.lang.Object
- - net.i2p.crypto.eddsa.EdDSAPrivateKey

- All Implemented Interfaces:
    Serializable, Key, PrivateKey, Destroyable, EdDSAKey

      public class EdDSAPrivateKey
      extends Object
      implements EdDSAKey, PrivateKey

  An EdDSA private key.

  For compatibility with older releases, decoding supports both RFC 8410 and an older draft specifications.

  See Also:
    RFC 8410, Older draft specification, Serialized Form

- - ### Field Summary

    - ### Fields inherited from interface net.i2p.crypto.eddsa.EdDSAKey

      `KEY_ALGORITHM`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EdDSAPrivateKey(EdDSAPrivateKeySpec spec)`
    `EdDSAPrivateKey(PKCS8EncodedKeySpec spec)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object o)`
    `byte[]` | `geta()`
    `GroupElement` | `getA()`
    `byte[]` | `getAbyte()`
    `String` | `getAlgorithm()`
    `byte[]` | `getEncoded()` Returns the private key in its canonical encoding.
    `String` | `getFormat()`
    `byte[]` | `getH()`
    `EdDSAParameterSpec` | `getParams()`
    `byte[]` | `getSeed()`
    `int` | `hashCode()`

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

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

    - ### Methods inherited from interface javax.security.auth.Destroyable

      `destroy, isDestroyed`

- - ### Constructor Detail

    - #### EdDSAPrivateKey

          public EdDSAPrivateKey(EdDSAPrivateKeySpec spec)

    - #### EdDSAPrivateKey

          public EdDSAPrivateKey(PKCS8EncodedKeySpec spec)
                          throws InvalidKeySpecException

      Throws:
        `InvalidKeySpecException`

  - ### Method Detail

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### geta

          public byte[] geta()

      Returns:
        the private key

    - #### getA

          public GroupElement getA()

      Returns:
        the public key

    - #### getAbyte

          public byte[] getAbyte()

      Returns:
        the public key

    - #### getAlgorithm

          public String getAlgorithm()

      Specified by:
        `getAlgorithm` in interface `Key`

    - #### getEncoded

          public byte[] getEncoded()

      Returns the private key in its canonical encoding.

      This implements the following specs:

      - General encoding: https://tools.ietf.org/html/rfc8410
      - Key encoding: https://tools.ietf.org/html/rfc8032

      This encodes the seed. It will return null if constructed from a spec which was directly constructed from H, in which case seed is null.

      For keys in older formats, decoding and then re-encoding is sufficient to migrate them to the canonical encoding.

      Relevant spec quotes:

            OneAsymmetricKey ::= SEQUENCE {
              version Version,
              privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
              privateKey PrivateKey,
              attributes [0] IMPLICIT Attributes OPTIONAL,
              ...,
              [[2: publicKey [1] IMPLICIT PublicKey OPTIONAL ]],
              ...
            }

            Version ::= INTEGER
            PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
            PrivateKey ::= OCTET STRING
            PublicKey ::= BIT STRING
            Attributes ::= SET OF Attribute

            ... when encoding a OneAsymmetricKey object, the private key is wrapped
            in a CurvePrivateKey object and wrapped by the OCTET STRING of the
            "privateKey" field.

            CurvePrivateKey ::= OCTET STRING

            AlgorithmIdentifier  ::=  SEQUENCE  {
              algorithm   OBJECT IDENTIFIER,
              parameters  ANY DEFINED BY algorithm OPTIONAL
            }

            For all of the OIDs, the parameters MUST be absent.

            id-Ed25519   OBJECT IDENTIFIER ::= { 1 3 101 112 }

      Specified by:
        `getEncoded` in interface `Key`
      Returns:
        48 bytes for Ed25519, null for other curves

    - #### getFormat

          public String getFormat()

      Specified by:
        `getFormat` in interface `Key`

    - #### getH

          public byte[] getH()

      Returns:
        the hash of the seed

    - #### getParams

          public EdDSAParameterSpec getParams()

      Specified by:
        `getParams` in interface `EdDSAKey`
      Returns:
        a parameter specification representing the EdDSA domain parameters for the key.

    - #### getSeed

          public byte[] getSeed()

      Returns:
        will be null if constructed from a spec which was directly constructed from H

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`