public final class ECPrivateKey extends AbstractECPrivateKey
ECPrivateKey
interface. It is derived from
PrivateKeyInfo
, which makes it suitable for use with PKCS#8.
PKCS#8 defines a syntax for encapsulating private key information:
PrivateKeyInfo ::= SEQUENCE { version Version, privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, privateKey PrivateKey attributes [0] IMPLICIT Attributes OPTIONAL }For EC private keys the syntax for the
privateKey
field is
defined by SEC1 [1]:
ECPrivateKey ::= SEQUENCE { version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1), privateKey OCTET STRING, parameters [0] ECDomainParameters {{ SECGCurveNames }} OPTIONAL, publicKey [1] BIT STRING OPTIONAL }and RFC 5915 [3]:
ECPrivateKey ::= SEQUENCE { version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1), privateKey OCTET STRING, parameters [0] ECParameters {{ NamedCurve }} OPTIONAL, publicKey [1] BIT STRING OPTIONAL }Both definitions are structurally equivalent; the parameters field may specify (by its ASN.1 object identifier) any elliptic curve supported by ECCelerate (e.g. as SEC 2 SECCurveName, or RFC 5480 NamedCurve). Although domain parameters shall be encoded by their curve oid, this implementation also supports full domain parameter encoding for interoperability reasons with other implementations.
parameters
is an optional
field, however, RFC 5915 requires that parameters MUST be included in the
ECPrivateKey structure. This may give some redundancy since the parameters
are also included in the PKCS#8 PrivateKeyInfo
privateKeyAlgorithm
AlgorithmID. For interoperability reasons
this implementation includes parameters in both the PKCS#8
privateKeyAlgorithm
AlgorithmID and the ECPrivateKey
parameters
field. ECParameterSpec.setDefaultOIDEncoding(true);
References:
[1] Certicom research. 2009. Standards for Efficient Cryptography - SEC 1:
Elliptic Curve Cryptography v2.0
[2] Certicom research. 2000. Standards for Efficient Cryptography - SEC 2:
Recommended elliptic curve domain parameters
[3] S. Turner (IECA), D. Brown (Certicom). 2010. RFC 5915: Elliptic Curve
Private Key Structure
[4] S. Turner, D. Brown, K. Yiu, R. Housley, T. Polk. 2009. RFC 5480:
Elliptic Curve Cryptography Subject Public Key Information
[5] An RSA Laboratories Technical Note. 1993. PKCS #8: Private-Key
Information Syntax Standard v2.1
ECKeyPairGenerator
,
ECKey
,
ECPrivateKeySpec
,
ECPublicKey
,
ECPublicKeySpec
,
Serialized FormModifier and Type | Field and Description |
---|---|
static iaik.asn1.INTEGER |
EC_PRIVATE_KEY_VERSION
the version field in the ASN.1 encoding
|
static iaik.asn1.ObjectID |
OID
object identifier for the ASN.1 structure
|
encodedPrivateKey_, params_, s_, w_
Constructor and Description |
---|
ECPrivateKey(byte[] encoded)
Constructs a new
ECPrivateKey from an encoded ASN.1 structure. |
ECPrivateKey(ECParameterSpec params,
BigInteger s)
Constructs a new
ECPrivateKey from a set of curve parameters and a
secret integer s . |
ECPrivateKey(ECParameterSpec params,
BigInteger s,
ECPoint publicKey)
Creates a new private key with the specified parameters.
|
ECPrivateKey(ECPrivateKey key)
Constructs a new
ECPrivateKey from a JDK private key. |
ECPrivateKey(ECPrivateKeySpec key)
Constructs a new
ECPrivateKey from a JDK ECPrivateKeySpec
object. |
ECPrivateKey(ECPrivateKeySpec key)
Constructs a new
ECPrivateKey from an IAIK ECPrivateKeySpec
object. |
Modifier and Type | Method and Description |
---|---|
protected void |
createEncodedPrivateKey()
Creates the ASN.1 private key structure following [1, Section C.4].
|
protected void |
decode(byte[] privateKey)
Decodes the DER encoded private key.
|
String |
getAlgorithm() |
int |
getKeyLength()
Returns the key length of this
ECKey . |
ECPublicKey |
getPublicKey()
Returns the corresponding
AbstractECPublicKey . |
static ECPrivateKey |
parse(byte[] privateKey)
This method parses an EC private key.
|
String |
toString() |
encode, equals, finalize, getParams, getS, hashCode
clone, createPrivateKeyInfo, decode, getAlgorithmID, getAttributes, getEncoded, getFormat, getPrivateKey, getPrivateKey, getPrivateKey, getPrivateKey, getPrivateKey, getPrivateKey, getPubKey, setAttributes, setPubKey, toASN1Object, writeTo
getEncoded, getFormat
destroy, isDestroyed
public static final iaik.asn1.INTEGER EC_PRIVATE_KEY_VERSION
public static final iaik.asn1.ObjectID OID
public ECPrivateKey(byte[] encoded) throws InvalidKeyException
ECPrivateKey
from an encoded ASN.1 structure.encoded
- the byte[]
holding the ASN.1 structureInvalidKeyException
- thrown if the given encoded key could not be decodedpublic ECPrivateKey(ECPrivateKeySpec key) throws InvalidCurveParameterSpecException
ECPrivateKey
from a JDK ECPrivateKeySpec
object.key
- the private key specInvalidCurveParameterSpecException
- if the associated curve parameters are not validpublic ECPrivateKey(ECPrivateKey key) throws InvalidCurveParameterSpecException
ECPrivateKey
from a JDK private key.key
- the private keyInvalidCurveParameterSpecException
- if the associated curve parameters are not validpublic ECPrivateKey(ECPrivateKeySpec key)
ECPrivateKey
from an IAIK ECPrivateKeySpec
object.key
- the private key specpublic ECPrivateKey(ECParameterSpec params, BigInteger s)
ECPrivateKey
from a set of curve parameters and a
secret integer s
.params
- the curve parameterss
- the private keypublic ECPrivateKey(ECParameterSpec params, BigInteger s, ECPoint publicKey)
params
- the domain parameterss
- the private keypublicKey
- the corresponding public key (may be null)public String getAlgorithm()
getAlgorithm
in interface Key
getAlgorithm
in class iaik.pkcs.pkcs8.PrivateKeyInfo
public static ECPrivateKey parse(byte[] privateKey) throws InvalidKeyException
parameters
field must be included.privateKey
- a "RAW" EC private keyInvalidKeyException
- if the given key is not an EC private key, is not properly
encoded or does not contain parameterspublic int getKeyLength()
ECKey
ECKey
.public ECPublicKey getPublicKey()
AbstractECPrivateKey
AbstractECPublicKey
.getPublicKey
in class AbstractECPrivateKey
AbstractECPublicKey
public String toString()
toString
in class iaik.pkcs.pkcs8.PrivateKeyInfo
protected void createEncodedPrivateKey()
ECPrivateKey ::= SEQUENCE { version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1), privateKey OCTET STRING, parameters [0] ECDomainParameters {{ SECGCurveNames }} OPTIONAL, publicKey [1] BIT STRING OPTIONAL }
createEncodedPrivateKey
in class AbstractECPrivateKey
protected void decode(byte[] privateKey) throws InvalidKeyException
decode
in class iaik.pkcs.pkcs8.PrivateKeyInfo
privateKey
- the DER byte array.InvalidKeyException
- if the provided key data is invalid.AbstractECPrivateKey.encode()
Copyright © 2011–2022 Stiftung SIC. All rights reserved.