public final class EcPublicKey extends PublicKeyInfo implements java.security.interfaces.ECPublicKey
An EC public key contains an EC public point and a set of EC domain parameters. The ASN.1 representation of an EC public key is defined in the X.509, ANSI and SEC standards as follows:
-- Defined in SEC 1: Elliptic Curve Cryptography
SubjectPublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier,
subjectPublicKey BIT STRING
-- Contains the encoded EC public point
}
ecPublicKeyType ALGORITHM ::= {
OID id-ecPublicKey PARAMS ECDomainParameters
}
id-ecPublicKey OBJECT IDENTIFIER ::= { 1 2 840 10045 2 1 }
The following additional EC key algorithm identifiers have also been defined. This release offers partial support for these additional EC key algorithm identifiers (enough for interoperability - the ability to consume public keys containing these algorithm identifiers without failure). The Toolkit will recognize them during decoding as valid EC public key algorithm identifiers, however, none of the algorithm restriction they imply are enforced. Additionally, the Toolkit does not yet offer any way to create or generate an EC public key containing one of these algorithm identifiers.
id-ecPublicKeyTypeRestricted OBJECT IDENTIFIER ::= { 1 2 840 10045 2 2 }
id-ecDH OBJECT IDENTIFIER ::= { 1 3 132 1 12 }
id-ecMQV OBJECT IDENTIFIER ::= { 1 3 132 1 13 }
Refer to EcParameterFactory for details on the EC domain parameters,
including a table of supported named EC domains as well as their ASN.1
specification. All three EC domain parameter formats are supported
('specified', 'named', and 'implicitCA'). Point compression is not supported.
Before the result of a cryptographic operation involving an EC public key is returned, a check must be performed to ensure that the public key is valid; this is called EC public key validation. All EC-based cryptographic algorithms provided by the Toolkit automatically perform EC public key validation prior to returning the result of any cryptographic operation that uses a public key.
The Toolkit's EC public key validation routine performs a set of checks on the EC public point and if any of these checks fail the public key is considered invalid and cannot be used. It employs an optimized version of the full public key validation routine described in NIST Special Publication 800-56A (March, 2007) Section 5.6.2.5.
Note: A prerequisite to the public key validation is having a valid
set of EC domain parameters. All EC-based cryptographic algorithms provided
by the Toolkit automatically validate the EC domain parameters associated
with an EC public key prior to performing EC public key validation. For
additional details on the EC domain parameter validation routine, refer to
EcParameterFactory
EcPrivateKey,
EcKeyPairGenerator,
EcKeyFactory,
Serialized Formpublic_key_algorithm| Constructor and Description |
|---|
EcPublicKey(byte[] ba)
A constructor; creates a new
EcPublicKey object by decoding
and parsing the passed in DER encoded ASN.1 SubjectPublicKeyInfo
structure. |
EcPublicKey(byte[] ba,
java.security.spec.ECParameterSpec configuredImplicitCaParams)
A constructor; creates a new
EcPublicKey object by decoding
and parsing the passed in DER encoded ASN.1 SubjectPublicKeyInfo
structure with support for providing 'implicitCA' EC domain parameter
values. |
EcPublicKey(java.security.spec.ECPoint w,
java.security.spec.ECParameterSpec params)
A constructor; creates a new
EcPublicKey object from the
provided public point and EC domain parameters. |
EcPublicKey(java.security.spec.ECPoint w,
java.security.spec.ECParameterSpec params,
boolean forceSpecifiedEcDomainParams)
A constructor; creates a new
EcPublicKey object from the
provided public point, EC domain parameters, and an indicator for
whether or not the domain parameters must be encoded in 'specified'
format . |
| Modifier and Type | Method and Description |
|---|---|
protected void |
decode(byte[] subjectPublicKey)
Decodes a DER encoded ASN.1 representation of an EC public key value (a
BIT STRING). |
static java.security.spec.ECPoint |
decodePoint(byte[] encodedEcPoint,
java.security.spec.EllipticCurve ellipticCurve)
Converts an EC point in binary encoded format to Sun JCA format.
|
protected byte[] |
encode()
Encodes a DER encoded ASN.1 representation of an EC public key value (a
BIT STRING). |
static byte[] |
encodePoint(java.security.spec.ECPoint ecPoint,
java.security.spec.EllipticCurve ellipticCurve)
Converts an EC point in Sun JCA format to binary encoded format.
|
java.lang.String |
getAlgorithm()
Returns the algorithm of this public key, which is 'EC'.
|
byte[] |
getEncoded()
Returns this DER encoding of this public key.
|
byte[] |
getEncoded(boolean forceSpecifiedEcDomainParams)
Encodes the public key using the force 'specified' indicator.
|
static byte[] |
getEncoded(java.security.interfaces.ECPublicKey publicKey,
EcParameterFormat format)
Encodes an EC public key using the requested EC domain parameter format.
|
byte[] |
getEncodedPoint()
Returns the encoded EC public point (the byte value of
SubjectPublicKey.subjectPublicKey). |
java.security.spec.ECParameterSpec |
getParams()
Returns the EC domain parameters associated with is EC public key.
|
java.security.spec.ECPoint |
getW()
Returns the EC public point
w (also referred to as
Q). |
createPublicKeyInfo, decode, equals, getFingerprint, getFormat, getPublicKey, getPublicKey, toASN1Object, toString, writeTopublic EcPublicKey(byte[] ba)
throws java.security.InvalidKeyException
EcPublicKey object by decoding
and parsing the passed in DER encoded ASN.1 SubjectPublicKeyInfo
structure.
An EC public key contains EC domain parameters in addition to the public
key value itself. Multiple EC domain parameter formats are supported
including 'specified', 'named', and 'implicitCA'. During decoding of an
EC public key, when EC domain parameters in 'implicitCA' format are
encountered, this must be interpreted to mean a specific set of EC domain
parameter values. For details on how 'implicitCA' EC domain parameters
are interpreted, refer to
EcPublicKey(byte[], ECParameterSpec).
ba - a DER encoded ASN.1 SubjectPublicKeyInfo structurejava.security.InvalidKeyException - if the DER encoded data passed in does not represent a DER
encoded ASN.1 SubjectPublicKeyInfo structure that contains an
EC public keypublic EcPublicKey(byte[] ba,
java.security.spec.ECParameterSpec configuredImplicitCaParams)
throws java.security.InvalidKeyException
EcPublicKey object by decoding
and parsing the passed in DER encoded ASN.1 SubjectPublicKeyInfo
structure with support for providing 'implicitCA' EC domain parameter
values.
An EC public key contains EC domain parameters in addition to the public key value itself. Multiple EC domain parameter formats are supported including 'specified', 'named', and 'implicitCA'. During decoding of an EC public key, when EC domain parameters in 'implicitCA' format are encountered, this must be interpreted to mean a specific set of EC domain parameter values. There are multiple ways of indicating the set of EC domain parameter values for 'implicitCA'; this constructor provides one way of doing so.
The following logic is used during a decode operation when 'implicitCA' domain parameters are encountered to determine the actual EC domain parameter values that should be used:
EcParameterFactory.setConfiguredImplicitCaParams(ECParameterSpec)
API.com.entrust.toolkit.security.crypto.ec.EcParameterFactory.configuredImplicitCaParamsDomainName
Java system property to a valid EC domain name.P-256 EC domain.ba - a DER encoded ASN.1 SubjectPublicKeyInfo structureconfiguredImplicitCaParams - the locally configured 'implicitCA' EC domain parameter values
(OPTIONAL)java.security.InvalidKeyException - if the DER encoded data passed in does not represent a DER
encoded ASN.1 SubjectPublicKeyInfo structure that contains an
EC public keypublic EcPublicKey(java.security.spec.ECPoint w,
java.security.spec.ECParameterSpec params)
EcPublicKey object from the
provided public point and EC domain parameters.w - the EC public point (also referred to as Q)params - the EC domain parameterspublic EcPublicKey(java.security.spec.ECPoint w,
java.security.spec.ECParameterSpec params,
boolean forceSpecifiedEcDomainParams)
EcPublicKey object from the
provided public point, EC domain parameters, and an indicator for
whether or not the domain parameters must be encoded in 'specified'
format .
EC domain parameters can be represented in ASN.1 with 'specified',
'named' or 'implicitCA' format. Refer to getEncoded() for
details on the EC domain parameter format that is used when encoding
the public key.
w - the EC public point (also referred to as Q)params - the EC domain parametersforceSpecifiedEcDomainParams - a force 'specified' indicator; true if the EC
domain parameters contained in this EC key must be encoded in
'specified' format; false otherwisepublic static byte[] encodePoint(java.security.spec.ECPoint ecPoint,
java.security.spec.EllipticCurve ellipticCurve)
The EC point encoding routine is taken from ANSI X9.62-2005 Section A.5.7, however, currently only uncompressed form is supported.
ANSI X9.62-2005 A.5.7
Point to Octet String
The octet string representation of the point at infinity O
shall be a single zero octet PC = 00.
An elliptic curve point P = (xP, yP) which is not the
point at infinity shall be represented as an octet string in one of the
following three forms:
P = (xP, yP) which is not the
point at infinity.xP to an octet string
XP. (see A.5)zP. (See A.3.1.3)02 to the single octet
PC if zP is 0, or the value
03 if zP is 1.PO = PC || XP.yP to an octet string
YP. (See A.5)04 to the single octet
PC.PO = PC || XP || YP.yP to an octet string
YP. (See A.5)zP. (See A.3.1.3)06 to the single octet
PC if zP is 0, or the value
07 if zP is 1.PO = PC || XP || YP.PO of length l + 1
octets if the compressed form is used, or of length 2l + 1
if the uncompressed or hybrid form is used.ecPoint - an EC point in Sun JCA formatellipticCurve - the elliptic curve that the EC point exists onpublic static java.security.spec.ECPoint decodePoint(byte[] encodedEcPoint,
java.security.spec.EllipticCurve ellipticCurve)
The EC point decoding routine is taken from ANSI X9.62-2005 Section A.5.8, however, currently only uncompressed form is supported and step 6 is not performed.
ANSI X9.62-2005 A.5.8
Octet String to Point
PO of length l + 1
octets if the compressed for is used, or of length 2l + 1
if the uncompressed or hybrid form is used, and field elements
a, b which define the elliptic curve over
Fq.PO as
follows: PO = PC || XP, where PC is a
single octet and XP is an octet string of length
l octets. If the uncompressed or hybrid form is used, then
parse PO as follows: PO = PC || XP || YP,
where PC is a single octet, and XP and
YP are octet strings each of length l
octets.XP to a field element xP.
(See A.5)PC is either 02 or
03. (It is an error if this is not the case.)zP to be equal to 0 if
PC = 02, or 1 if PC = 03.(xP, zP) to an elliptic curve point
(xP, yP). (See A.3.1.3)PC is 04. (It is an error
if this is not the case.)YP to a field element yP.
(See A.5).PC is either 06 or
07. (It is an error if this is not the case.)YP to a field element yP (See
A.5)zP to be equal to 0 if
PC = 06, or 1 if PC = 07(xP, zP') from
(xP, yP). (See A.3.1.3). Verify that
(xP, zP) = (xP, zP'). (It is an error if this is not the
case).(xP, yP')
from the compressed point (xP, zP). (see A.3.1.3). Check
that (xP, yP) = (xP, yP'). (It is an error if this is not
the case).q is a prime, verify that
yP^2 = xP^3 + axP + b. (It is an error if this is not the
case). If q = 2^m, verify that
yP^2 + xPyP = Xp^3 + aXp^2 + b. (It is an error if this
is not the case).P = (xP, yP).P = (xP, yP), not the point
at infinity.encodedEcPoint - an EC point in binary encoded formatellipticCurve - the elliptic curve that the EC point exists onjava.lang.IllegalArgumentException - if an error occurs during point decoding (the binary encoded
EC point is invalid)public static byte[] getEncoded(java.security.interfaces.ECPublicKey publicKey,
EcParameterFormat format)
throws java.lang.IllegalArgumentException,
UnsupportedECDomainException
One component of a DER encoded EC public key are the EC domain parameters
and these parameters can be represented in ASN.1 using different formats.
This API allows the caller to control the EC domain parameter format that
is used when encoding the EC domain parameters contained in the EC public
key. Refer to
EcParameterFactory.getInstance(ECParameterSpec, EcParameterFormat)
for details on the supported EC domain parameters formats.
publicKey - an EC public keyformat - requested EC domain parameter formatjava.lang.IllegalArgumentException - if the EC public key or the parameter format are not provided
(missing)UnsupportedECDomainException - if the 'named' format is requested and the EC domain
parameter contained in the provided EC public key do not
match one of the supported 'named' EC domainspublic java.security.spec.ECPoint getW()
w (also referred to as
Q).getW in interface java.security.interfaces.ECPublicKeypublic java.lang.String getAlgorithm()
getAlgorithm in interface java.security.KeygetAlgorithm in class PublicKeyInfopublic java.security.spec.ECParameterSpec getParams()
getParams in interface java.security.interfaces.ECKeyprotected void decode(byte[] subjectPublicKey)
throws java.security.InvalidKeyException
BIT STRING).
The DER encoded EC public key value is decoded and parsed and the EC public point it contains is stored internally.
decode in class PublicKeyInfosubjectPublicKey - a DER encoded ASN.1 representation of an EC public key valuejava.security.InvalidKeyException - if the DER encoded data passed in does not represent a DER
encoded ASN.1 BIT STRING structure that
contains an EC public keyprotected byte[] encode()
BIT STRING).encode in class PublicKeyInfopublic byte[] getEncodedPoint()
SubjectPublicKey.subjectPublicKey).public byte[] getEncoded()
Refer to getEncoded(boolean) for details on the EC domain
parameter format that is used during encoding. This API has the same
effect as calling getEncoded(false).
getEncoded in interface java.security.KeygetEncoded in class PublicKeyInfopublic byte[] getEncoded(boolean forceSpecifiedEcDomainParams)
One component of the DER encoded public key is the EC domain parameters. EC domain parameters can be represented in ASN.1 using 'specified', 'named' or 'implicitCA' format. Because the most widely supported EC domain parameter format is 'specified', for interoperability reasons it can be desirable to force a 'specified' encoding. This implementation allows the EC domain parameter format used during encoding to be configured; the following logic is used during an encode operation to decide the format in which the EC domain parameters that the key contains should be encoded:
true,
then the 'specified' format is used.true was provided
through the constructor, then the 'specified' format is used.com.entrust.toolkit.security.crypto.ec.EcKey.forceSpecifiedEcDomainParams=true
or
com.entrust.toolkit.security.crypto.ec.EcPublicKey.forceSpecifiedEcDomainParams=true
Java system properties are set as indicated, then the 'specified' format
is used.EcParameterSpecWithName supports 'specified', 'named', and
'implicitCA' formats, while EcParameterSpec only supports
'specified' format.forceSpecifiedEcDomainParams - a force 'specified' indicator; true if the EC
domain parameters contained in this EC key must be encoded in
'specified' format; false otherwise