Class EdDSAPublicKey

  • All Implemented Interfaces:
    java.io.Serializable, java.security.Key, java.security.PublicKey, EdDSAKey

    public class EdDSAPublicKey
    extends java.lang.Object
    implements EdDSAKey, java.security.PublicKey
    An EdDSA public key.

    Warning: Public key encoding is is based on the current curdle WG draft, and is subject to change. See getEncoded().

    For compatibility with older releases, decoding supports both the old and new draft specifications. See decode().

    Ref: https://tools.ietf.org/html/draft-ietf-curdle-pkix-04

    Old Ref: https://tools.ietf.org/html/draft-josefsson-pkix-eddsa-04

    See Also:
    Serialized Form
    • Constructor Detail

      • EdDSAPublicKey

        public EdDSAPublicKey​(java.security.spec.X509EncodedKeySpec spec)
                       throws java.security.spec.InvalidKeySpecException
        Throws:
        java.security.spec.InvalidKeySpecException
    • Method Detail

      • getAlgorithm

        public java.lang.String getAlgorithm()
        Specified by:
        getAlgorithm in interface java.security.Key
      • getFormat

        public java.lang.String getFormat()
        Specified by:
        getFormat in interface java.security.Key
      • getEncoded

        public byte[] getEncoded()
        Returns the public key in its canonical encoding.

        This implements the following specs:

        • General encoding: https://tools.ietf.org/html/draft-ietf-curdle-pkix-04
        • Key encoding: https://tools.ietf.org/html/rfc8032

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

        Relevant spec quotes:
          In the X.509 certificate, the subjectPublicKeyInfo field has the
          SubjectPublicKeyInfo type, which has the following ASN.1 syntax:
        
          SubjectPublicKeyInfo  ::=  SEQUENCE  {
            algorithm         AlgorithmIdentifier,
            subjectPublicKey  BIT 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 java.security.Key
        Returns:
        44 bytes for Ed25519, null for other curves
      • decode

        private static byte[] decode​(byte[] d)
                              throws java.security.spec.InvalidKeySpecException
        Extracts the public key bytes from the provided encoding.

        This will decode data conforming to the current spec at https://tools.ietf.org/html/draft-ietf-curdle-pkix-04 or the old spec at https://tools.ietf.org/html/draft-josefsson-pkix-eddsa-04.

        Contrary to draft-ietf-curdle-pkix-04, it WILL accept a parameter value of NULL, as it is required for interoperability with the default Java keystore. Other implementations MUST NOT copy this behaviour from here unless they also need to read keys from the default Java keystore.

        This is really dumb for now. It does not use a general-purpose ASN.1 decoder. See also getEncoded().

        Returns:
        32 bytes for Ed25519, throws for other curves
        Throws:
        java.security.spec.InvalidKeySpecException
      • getParams

        public EdDSAParameterSpec getParams()
        Specified by:
        getParams in interface EdDSAKey
        Returns:
        a parameter specification representing the EdDSA domain parameters for the key.
      • getAbyte

        public byte[] getAbyte()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object