Class EdDSAPrivateKey
- java.lang.Object
-
- net.i2p.crypto.eddsa.EdDSAPrivateKey
-
- All Implemented Interfaces:
java.io.Serializable
,java.security.Key
,java.security.PrivateKey
,javax.security.auth.Destroyable
,EdDSAKey
public class EdDSAPrivateKey extends java.lang.Object implements EdDSAKey, java.security.PrivateKey
An EdDSA private key.Warning: Private key encoding 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
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
a
private GroupElement
A
private byte[]
Abyte
private EdDSAParameterSpec
edDsaSpec
private byte[]
h
private static int
IDLEN_BYTE
private static int
OID_BYTE
private static int
OID_ED25519
private static int
OID_OLD
private byte[]
seed
private static long
serialVersionUID
-
Fields inherited from interface net.i2p.crypto.eddsa.EdDSAKey
KEY_ALGORITHM
-
-
Constructor Summary
Constructors Constructor Description EdDSAPrivateKey(java.security.spec.PKCS8EncodedKeySpec spec)
EdDSAPrivateKey(EdDSAPrivateKeySpec spec)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static byte[]
decode(byte[] d)
Extracts the private key bytes from the provided encoding.boolean
equals(java.lang.Object o)
byte[]
geta()
GroupElement
getA()
byte[]
getAbyte()
java.lang.String
getAlgorithm()
byte[]
getEncoded()
Returns the public key in its canonical encoding.java.lang.String
getFormat()
byte[]
getH()
EdDSAParameterSpec
getParams()
byte[]
getSeed()
int
hashCode()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
seed
private final byte[] seed
-
h
private final byte[] h
-
a
private final byte[] a
-
A
private final GroupElement A
-
Abyte
private final byte[] Abyte
-
edDsaSpec
private final EdDSAParameterSpec edDsaSpec
-
OID_OLD
private static final int OID_OLD
- See Also:
- Constant Field Values
-
OID_ED25519
private static final int OID_ED25519
- See Also:
- Constant Field Values
-
OID_BYTE
private static final int OID_BYTE
- See Also:
- Constant Field Values
-
IDLEN_BYTE
private static final int IDLEN_BYTE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EdDSAPrivateKey
public EdDSAPrivateKey(EdDSAPrivateKeySpec spec)
-
EdDSAPrivateKey
public EdDSAPrivateKey(java.security.spec.PKCS8EncodedKeySpec spec) throws java.security.spec.InvalidKeySpecException
- Throws:
java.security.spec.InvalidKeySpecException
-
-
Method Detail
-
getAlgorithm
public java.lang.String getAlgorithm()
- Specified by:
getAlgorithm
in interfacejava.security.Key
-
getFormat
public java.lang.String getFormat()
- Specified by:
getFormat
in interfacejava.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
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] Attributes OPTIONAL, ..., [[2: publicKey [1] PublicKey OPTIONAL ]], ... } Version ::= INTEGER PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier PrivateKey ::= OCTET STRING PublicKey ::= OCTET 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 interfacejava.security.Key
- Returns:
- 48 bytes for Ed25519, null for other curves
-
decode
private static byte[] decode(byte[] d) throws java.security.spec.InvalidKeySpecException
Extracts the private 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 as inferred from 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()
-
getSeed
public byte[] getSeed()
- Returns:
- will be null if constructed from a spec which was directly constructed from H
-
getH
public byte[] getH()
- Returns:
- the hash of the seed
-
geta
public byte[] geta()
- Returns:
- the private key
-
getA
public GroupElement getA()
- Returns:
- the public key
-
getAbyte
public byte[] getAbyte()
- Returns:
- the public key
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
-