|
|||||||||
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()
Empty default Constructor. |
Method Summary | |
protected Key |
engineDoPhase(Key key,
boolean lastPhase)
Returns the key resulting from the next phase of this DH key agreement. |
protected byte[] |
engineGenerateSecret()
Returns the shared secret finally generated by this DH key agreement. |
protected 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. |
protected SecretKey |
engineGenerateSecret(String algorithm)
Returns the shared secret finally generated by this DH key agreement as SecretKey to be used for the specified secret key algorithm. |
protected void |
engineInit(Key key,
AlgorithmParameterSpec params,
SecureRandom random)
Initializes this Diffie Helman KeyAgreement with the given key, algorithm parameters, and random seed. |
protected 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()
KeyAgreement.getInstance("DH");for generating an DHKeyAgreement object.
Method Detail |
protected 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).
engineInit
in class KeyAgreementSpi
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 seedInvalidKeyException
- if the given key cannot be used for this key agreementprotected 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).
engineInit
in class KeyAgreementSpi
key
- the private DH key information of the entity involved in the key
agreementrandom
- the random seedInvalidKeyException
- if the given key cannot be used for this key agreementprotected Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException
engineDoPhase
in class KeyAgreementSpi
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 phaseInvalidKeyException
- if the given key cannot be used for this key
agreement algorithm / phaseIllegalStateException
- if the given phase cannot be performed in
this state of the key agreement procedureprotected SecretKey engineGenerateSecret(String algorithm) throws 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:
engineGenerateSecret
in class KeyAgreementSpi
algorithm
- the name of the secret key algorithm for which the generated
secret key shall be usedIllegalStateException
- if this key agreement procedure yet is not ready for being finished
by generating the shared secretNoSuchAlgorithmException
- if the given secret key algorithm is not supportedInvalidKeyException
- if the generated shared secret cannot be returned as SecretKey
matching to the given algorithmprotected int engineGenerateSecret(byte[] sharedSecret, int offset) throws 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.
engineGenerateSecret
in class KeyAgreementSpi
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 secretIllegalStateException
- if this key agreement procedure yet is not ready
for being finished by generating the shared secretShortBufferException
- if the given output buffer is too small for holding
the secretprotected byte[] engineGenerateSecret() throws 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.
engineGenerateSecret
in class KeyAgreementSpi
IllegalStateException
- if this key agreement procedure yet is
not ready for being finished by generating
the shared secret
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |