- All Implemented Interfaces:
Serializable, AsymmetricKey, BinaryEncodablePREVIEW, Key, PublicKey, EdDSAKey
For compatibility with older releases, decoding supports both RFC 8410 and an older draft specification.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final GroupElementThe public key point.private final byte[]The encoded public key (Abyte).private GroupElementThe negated public key point, lazily initialized.private final EdDSAParameterSpecEd dsa spec.private static final intOffset of the identifier length in the encoded key.private static final intOffset of the object identifier in the encoded key.private static final intObject identifier for Ed25519.private static final intFirst object identifier in the 1.3.101.xxx range.private static final longPinned for serialized-form compatibility.Fields inherited from interface EdDSAKey
KEY_ALGORITHMConstructor Summary
ConstructorsConstructorDescriptionCreate from X.509.Takes the public point A and its curve parameters from the spec.Method Summary
Modifier and TypeMethodDescriptionprivate static byte[]decode(byte[] d) Extracts the public key bytes from the provided encoding.booleanWhether this key is equal to the given key.getA()The public key point A.byte[]getAbyte()The encoded public key.The reported algorithm name for all EdDSA keys.byte[]Returns the public key in its canonical encoding.The encoding format of the key.The negated public key point.The EdDSA domain parameters for the key.inthashCode()Hash code of the public key bytes, for use in hash tables.
Field Details
serialVersionUID
private static final long serialVersionUIDPinned for serialized-form compatibility.- See Also:
A
The public key point.Aneg
The negated public key point, lazily initialized. Volatile for safe publication across verify threads.Abyte
private final byte[] AbyteThe encoded public key (Abyte).edDsaSpec
Ed dsa spec.OID_OLD
private static final int OID_OLDFirst object identifier in the 1.3.101.xxx range.- See Also:
OID_ED25519
OID_BYTE
private static final int OID_BYTEOffset of the object identifier in the encoded key.- See Also:
IDLEN_BYTE
private static final int IDLEN_BYTEOffset of the identifier length in the encoded key.- See Also:
Constructor Details
EdDSAPublicKey
Takes the public point A and its curve parameters from the spec.- Parameters:
spec- the public key specification
EdDSAPublicKey
Create from X.509.- Parameters:
spec- the X.509 key specification- Throws:
InvalidKeySpecException- if the spec is invalid
Method Details
getAlgorithm
The reported algorithm name for all EdDSA keys.- Specified by:
getAlgorithmin interfaceKey- Returns:
- the JCA algorithm name shared by all EdDSA keys, "EdDSA"
getFormat
getEncoded
public byte[] getEncoded()Returns the public key in its canonical encoding.This implements the following specs:
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:
getEncodedin interfaceKey- Returns:
- 44 bytes for Ed25519, null for other curves
decode
Extracts the public key bytes from the provided encoding.This will decode data conforming to RFC 8410 or the older draft spec at https://tools.ietf.org/html/draft-josefsson-pkix-eddsa-04.
Per RFC 8410 section 3, this function 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().- Parameters:
d- the encoded key bytes from the keystore- Returns:
- 32 bytes for Ed25519, throws for other curves
- Throws:
InvalidKeySpecException- if the encoding is not a supported EdDSA key spec
getParams
The EdDSA domain parameters for the key.- Specified by:
getParamsin interfaceAsymmetricKey- Specified by:
getParamsin interfaceEdDSAKey- Returns:
- the EdDSAParameterSpec naming the curve and hash algorithm
getA
getNegativeA
The negated public key point.- Returns:
- -A, computed on first use and cached
getAbyte
public byte[] getAbyte()The encoded public key.- Returns:
- The public key bytes.
hashCode
equals