|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--javax.crypto.KeyAgreementSpi
|
+--iaik.security.dh.DHKeyAgreement
This class extends javax.crypto.KeyAgreementSpi for providing the
functionality of a Diffie Hellman key agreement as specified by
PKCS#3.
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 DHPrivateKey for bringing in the required private information. A DH Hellman private
key maybe generated using a proper key pair generator, e.g.:
KeyPairGnerator dh_key_gen = KeyPairGenerator.getInstance("DH");
dh_key_gen.initialize(1024);
KeyPair dh_key_pair = dh_key_gen.generateKeyPair();
DHPrivateKey dh_priv_key = (DHPrivateKey)dh_key_pair.getPrivate();
KeyAgreement dh_key_agreement = KeyAgreement.getInstance("DH");
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();
KeyAgreement,
DHGenParameterSpec,
DHParameterSpec,
DHPrivateKeySpec,
DHPublicKeySpec,
KeyPairGenerator,
KeyPair,
DHPublicKey,
DHPrivateKey,
DHKeyPairGenerator,
DHKeyFactory,
DHParameters,
DHParameterGenerator| Constructor Summary | |
DHKeyAgreement()
|
|
| Method Summary | |
Key |
engineDoPhase(Key key,
boolean lastPhase)
Returns the key resulting from the next phase of this DH key agreement. |
byte[] |
engineGenerateSecret()
Returns the shared secret finally generated by this DH key agreement. |
int |
engineGenerateSecret(byte[] sharedSecret,
int offset)
Generates the shared secret finishing this DH key agreement procedure and writes it into the given byte array, beginning at the given offset position. |
SecretKey |
engineGenerateSecret(java.lang.String algorithm)
Returns the shared secret finally generated by this DH key agreement as SecretKey to be used for the specified secret key algorithm. |
void |
engineInit(Key key,
AlgorithmParameterSpec params,
SecureRandom random)
Initializes this Diffie Helman KeyAgreement with the given key, algorithm parameters, and random seed. |
void |
engineInit(Key key,
SecureRandom random)
Initializes this Diffie Hallman KeyAgreement with the given key and random seed, where the given key constitutes the private DH key (including all required algorithm parameters) of some entity being involved in this key agreement procedure. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public DHKeyAgreement()
| Method Detail |
public void engineInit(Key key,
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidKeyException
The given key constitutes the private DH key of some entity being involved
in this DH key agreement procedure. Each entity being involved in a DH key
agreement process has to create a KeyAgreement object by using a proper
getInstance factory method (e.g.
KeyAgreement.getInstance("DH");) and subsequently initialize
it with the entity´s private DH key for bringing in the private information
which will be accessed when required during any phase of the key agreement
process. Any key material later supplied to any of the doPhase
methods will represent public key material of another participated entity
or key material resulting from some previously performed phase (if there
are more than two entities involved in the key agreement).
key - the private DH key information of the entity involved in the
key agreementparams - the algorithm parameter specification used for this key
agreement algorithmrandom - the random seed
public void engineInit(Key key,
SecureRandom random)
throws InvalidKeyException
Each entity being involved in a DH key agreement process has to create a
KeyAgreement object by using a proper getInstance factory
method (e.g. KeyAgreement.getInstance("DH");) and
subsequently initialize it with the entity´s private DH key for bringing
in the private information which will be accessed when required during any
phase of the key agreement process. Any key material later supplied to any
of the doPhase methods will represent public key material of
another participated entity or key material resulting from some previously
performed phase (if there are more than two entities involved in the key
agreement).
key - the private DH key information of the entity involved in the key
agreementrandom - the random seed
public Key engineDoPhase(Key key,
boolean lastPhase)
throws InvalidKeyException,
java.lang.IllegalStateException
key - the required key for this phase, supplied by some other entity
involved in this key agreementlastPhase - true if this is the last phase of this key
agreemant, false if notnull if no key
is returned by this phase
public SecretKey engineGenerateSecret(java.lang.String algorithm)
throws java.lang.IllegalStateException,
NoSuchAlgorithmException,
InvalidKeyException
After creating the shared secret, this KeyAgreement object is reset for being able to be used for further key agreements, either by using the same private key information as specified at the beginning of the key agreement, or using new parameters by properly initializing this KeyAgreement object again.
At this time the following algorithms are supported:
algorithm - the name of the secret key algorithm for which the generated
secret key shall be used
public int engineGenerateSecret(byte[] sharedSecret,
int offset)
throws java.lang.IllegalStateException,
ShortBufferException
After creating the shared secret, this KeyAgreement object is reset for being able to be used for further key agreements, either by using the same private key information as specified at the beginning of the key agreement, or using new parameters by properly initializing this KeyAgreement object again.
sharedSecret - the byte array to which the generated secret has to be writtenoffset - the offset indicating the start position within the output byte array
to which to write the generated shared secret
public byte[] engineGenerateSecret()
throws java.lang.IllegalStateException
After creating the shared secret, this DHKeyAgreement object is reset for being able to be used for further key agreements, either by using the same private key information as specified at the beginning of the key agreement, or using new parameters by properly initializing this KeyAgreement object again.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||