public class ESDHPublicKey extends PublicKeyInfo implements javax.crypto.interfaces.DHPublicKey, java.io.Serializable
iaik.x509.PublicKeyInfo for supporting ESDH public
keys to be used within X.509 certificates .
????????????????????????????????????????????????????????????????????????????????????
This class implements
the javax.crypto.interfaces.DHPublicKey interface for providing the
functionality of a public key as used within ESDH key agreement.
????????????????????????????????????????????????????????????????????????????????????
The Diffie Hellman algorithm constitutes a key-exchange (or key-agreement) algorithm where some entities communicate according to a predescribed protocol for generating a shared secret only known by them.
The Diffie Hellman algorithm has been the first public-key algorithm. It only can be used for key-agreement, but not for data encrypting and decrypting.
PKCS#3 describes a
method for implementing the Diffie Hellman key agreement where two entities use
general Diffie Hellman parameters (an odd prime p, an integer base
g satisfying 0 < g < p, and
optionally an integer l prescribing the length of the private value),
generated from some central authority (which may be an entity itself), to perform
two phases of the key agreement protocol:
x satisfying
0 < x < p-1. If the central authority has
prescribed the length l of the private value x,
it has to fulfill 2(l-1) <= x < 2l. From
the private value, the public value y is created by doing
y = (gx)(mod p) with 0 < y < p.
Subsequently each entity sends the public value just created to the other entity
involved in the key agreement.
y' received from the other entity to
finally create the shared secret z from the own private value x:
z = (y'x)(mod p) with 0 < z < p.
There may be more than only two entities involved into a Diffie Hellman key agreement.
Any application wishing to be participated into a Diffie Hellman key agreement has to
instantiate the javax.crypto.KeyAgreement class and initialize it with
its ESDHPrivateKey for bringing in the required private information. A ESDH Hellman
private key maybe generated using a proper key pair generator, e.g.:
KeyPairGnerator dh_key_gen = KeyPairGenerator.getInstance("ESDH");
dh_key_gen.initialize(1024);
KeyPair dh_key_pair = dh_key_gen.generateKeyPair();
ESDHPrivateKey dh_priv_key = (ESDHPrivateKey)dh_key_pair.getPrivate();
KeyAgreement dh_key_agreement = KeyAgreement.getInstance("ESDH");
dh_key_agreement.init(dh_priv_key);
Each phase of a key agreement is performed by a call to the doPhase
method, supplied with some other entity's public key or some intermediate
key resulting from the last phase. When calling doPhase, it has
to be specified whether to perform already the last phase of the key agreement
or not by setting the lastPhase parameter to true
or false:
dh_key_agreement.doPhase(dhPubKey_from_other_entity, true);Actually generating the shared secret is done by calling the
generateSecret method:
byte[] shared_secret = dh_key_agreemant.generateSecret();
PublicKeyInfo,
DHPublicKey,
KeyAgreement,
ESDHParameterSpec,
ESDHPrivateKeySpec,
ESDHPublicKeySpec,
KeyPairGenerator,
KeyPair,
ESDHPrivateKey,
ESDHKeyPairGenerator,
ESDHKeyFactory,
ESDHParameters,
ESDHParameterGenerator,
ESDHKeyAgreement,
Serialized Formpublic_key_algorithm| Constructor and Description |
|---|
ESDHPublicKey(ASN1Object obj)
Creates a new ESDHPublicKey from the given ASN.1 object.
|
ESDHPublicKey(java.math.BigInteger y,
ESDHParameterSpec parameters)
Creates a new ESDHPublicKey from public key value and ESDH parameter specification
|
ESDHPublicKey(byte[] pk)
Creates a new ESDHPublicKey from the given DER encoded byte array.
|
ESDHPublicKey(ESDHPublicKeySpec keySpec)
Creates a new ESDHPublicKey from the given ESDHPublicKeySpec representing
the ESDH public key value y, and the values p, g, q, j (if available) and
seed and pgenCounter (if available).
|
ESDHPublicKey(java.io.InputStream is)
Creates a new ESDHPublicKey from an InputStream.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
decode(byte[] publicKey)
Decodes an ESDHPublicKey, encoded in DER format.
|
protected byte[] |
encode()
Returns this ESDH public key as DER encoded ASN.1 object.
|
java.lang.String |
getAlgorithm()
Returns the name of the appertaining algorithm.
|
byte[] |
getFingerprint()
Returns the fingerprint of this ESDH public key.
|
javax.crypto.spec.DHParameterSpec |
getParams()
Returns the key parameters.
|
java.math.BigInteger |
getY()
Returns the public value
y as BigInteger. |
int |
hashCode()
Returns a hash code for this object.
|
java.lang.String |
toString()
Returns a string that represents the contents of this public key.
|
createPublicKeyInfo, decode, equals, getEncoded, getFormat, getPublicKey, getPublicKey, toASN1Object, writeTopublic ESDHPublicKey(java.math.BigInteger y,
ESDHParameterSpec parameters)
y - the BigInteger value representing the ESDH public key value yparameters - the ESDH parameters p (prime modulus), g (base generator),
prime factor q, the subgroup factor
j (if available) and the seed seed
and pgenCounter pgenCounter (if available)
as ESDHParameterSpecESDHParameterSpecpublic ESDHPublicKey(ESDHPublicKeySpec keySpec)
keySpec - the ESDHPublicKeySpec representing the public key value y,
the prime modulus p, the base generator g,
the subgroup factor j (if available) and the seed
seed and pgenCounter pgenCounter (if available)ESDHPublicKeySpecpublic ESDHPublicKey(byte[] pk)
throws java.security.InvalidKeyException
This constructor may be used for parsing an already exisiting
ESDH public key, wrapped into a X.509 PublicKeyInfo that is supplied as DER encoded byte array.
pk - the byte array holding the DER encoded public key infojava.security.InvalidKeyException - if something is wrong with the key encodingpublic ESDHPublicKey(ASN1Object obj) throws java.security.InvalidKeyException
PublicKeyInfo holding the ESDH public key.
obj - the public key ASN.1 data structurejava.security.InvalidKeyException - if something is wrong with the key encodingpublic ESDHPublicKey(java.io.InputStream is)
throws java.io.IOException,
java.security.InvalidKeyException
This constructor may be used for parsing an already exisiting
ESDH public key, wrapped into a X.509 PublicKeyInfo that is supplied as DER encoded byte array.
is - the input stream with the data to be read to initialize the public keyjava.io.IOException - if an I/O error occursjava.security.InvalidKeyException - if something is wrong with the key encodingprotected void decode(byte[] publicKey)
throws java.security.InvalidKeyException
From the given DER encoded byte array an ASN.1 object is created and parsed for
the public key value y and the ESDH parameters prime p
and base g, prime factor q, the subgroup factor
j (if available) and the seed seed and pgenCounter
pgenCounter (if available).
This method is protected and typically will not be used by an application. Rather
it is used by the parent X.509 PublicKeyInfo class for decoding the inherent ESDH public key.
decode in class PublicKeyInfopublicKey - the public key as DER encoded ASN.1 objectjava.security.InvalidKeyException - if the given key is not a ESDH public keyprotected byte[] encode()
This method is protected and typically will not be used by an application. Rather
it is used by the parent X.509 PublicKeyInfo class for encoding the inherent ESDH public key.
encode in class PublicKeyInfopublic java.lang.String getAlgorithm()
getAlgorithm in interface java.security.KeygetAlgorithm in class PublicKeyInfopublic java.math.BigInteger getY()
y as BigInteger.
getY in interface javax.crypto.interfaces.DHPublicKeyy as BigIntegerpublic javax.crypto.spec.DHParameterSpec getParams()
getParams in interface javax.crypto.interfaces.DHKeypublic byte[] getFingerprint()
getFingerprint in class PublicKeyInfopublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class PublicKeyInfo