- All Implemented Interfaces:
Serializable, AsymmetricKey, BinaryEncodablePREVIEW, Key, PrivateKey, Destroyable, EdDSAKey
For compatibility with older releases, decoding supports both RFC 8410 and an older draft specifications.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]The private scalar, the first 32 bytes of H.private final GroupElementThe public key point.private final byte[]The encoded public key (Abyte).private final EdDSAParameterSpecEd dsa spec.private final byte[]The 64-byte hash of the seed.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 final byte[]The 32-byte seed, or null if constructed from H.private static final longPinned for serialized-form compatibility.Fields inherited from interface EdDSAKey
KEY_ALGORITHMConstructor Summary
ConstructorsConstructorDescriptionCreate from PKCS#8.Unpacks a private key specification, encoding the public point as Abyte.Method Summary
Modifier and TypeMethodDescriptionprivate static byte[]decode(byte[] d) Extracts the private key bytes from the provided encoding.booleanWhether this key is equal to the given key.byte[]geta()The private scalar, the first 32 bytes of H.getA()The public key point.byte[]getAbyte()The encoded public key.The reported algorithm name for all EdDSA keys.byte[]Returns the private key in its canonical encoding.The encoding format of the key.byte[]getH()The 64-byte hash of the seed.The EdDSA domain parameters for the key.byte[]getSeed()The 32-byte seed.inthashCode()Hash code of the seed, for use in hash tables.Methods inherited from interface Destroyable
destroy, isDestroyed
Field Details
serialVersionUID
private static final long serialVersionUIDPinned for serialized-form compatibility.- See Also:
seed
private final byte[] seedThe 32-byte seed, or null if constructed from H.h
private final byte[] hThe 64-byte hash of the seed.a
private final byte[] aThe private scalar, the first 32 bytes of H.A
The public key point.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
EdDSAPrivateKey
Unpacks a private key specification, encoding the public point as Abyte.- Parameters:
spec- the private key specification
EdDSAPrivateKey
Create from PKCS#8.- Parameters:
spec- the PKCS#8 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 algorithm name
EdDSA, the same for every curve
getFormat
The encoding format of the key.- Specified by:
getFormatin interfaceKey- Returns:
- the encoding name
PKCS#8, matchinggetEncoded()
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 STRINGAlgorithmIdentifier ::= 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:
- 48 bytes for Ed25519, null for other curves
decode
Extracts the private key bytes from the provided encoding.This will decode data conforming to RFC 8410 or as inferred from 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 DER-encoded private key bytes to decode- Returns:
- 32 bytes for Ed25519, throws for other curves
- Throws:
InvalidKeySpecException- if the encoding is invalid or the curve is not Ed25519
getParams
The EdDSA domain parameters for the key.- Specified by:
getParamsin interfaceAsymmetricKey- Specified by:
getParamsin interfaceEdDSAKey- Returns:
- the curve parameters this key was built with, never null
getSeed
public byte[] getSeed()The 32-byte seed.- Returns:
- Will be null if constructed from a spec which was directly constructed from H.
getH
public byte[] getH()The 64-byte hash of the seed.- Returns:
- The hash of the seed.
geta
public byte[] geta()The private scalar, the first 32 bytes of H.- Returns:
- The private key.
getA
getAbyte
public byte[] getAbyte()The encoded public key.- Returns:
- The public key.
hashCode
equals