javax.crypto
Class KeyAgreement
Key agreement is a method in which two or more parties may agree on a
secret key for symmetric cryptography or message authentication
without transmitting any secrets in the clear. Key agreement
algorithms typically use a public/private
key pair, and the
public key (along with some additional information) is sent across
untrusted networks.
The most common form of key agreement used today is the
Diffie-Hellman key exchange algorithm, described in
PKCS #3 -
Diffie Hellman Key Agreement Standard.
Key | doPhase(Key key, boolean lastPhase) - Do a phase in the key agreement.
|
byte[] | generateSecret() - Generate the shared secret in a new byte array.
|
int | generateSecret(byte[] sharedSecret, int offset) - Generate the shared secret and store it into the supplied array.
|
SecretKey | generateSecret(String algorithm) - Generate the shared secret and return it as an appropriate
SecretKey .
|
String | getAlgorithm() - Return the name of this key-agreement algorithm.
|
static KeyAgreement | getInstance(String algorithm) - Get an implementation of an algorithm from the first provider that
implements it.
|
static KeyAgreement | getInstance(String algorithm, String provider) - Return an implementation of an algorithm from a named provider.
|
static KeyAgreement | getInstance(String algorithm, Provider provider) - Return an implementation of an algorithm from a specific provider.
|
Provider | getProvider() - Return the provider of the underlying implementation.
|
void | init(Key key) - Initialize this key agreement with a key.
|
void | init(Key key, SecureRandom random) - Initialize this key agreement with a key and a source of
randomness.
|
void | init(Key key, AlgorithmParameterSpec params) - Initialize this key agreement with a key and parameters.
|
void | init(Key key, AlgorithmParameterSpec params, SecureRandom random) - Initialize this key agreement with a key, parameters, and source of
randomness.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
doPhase
public final Key doPhase(Key key,
boolean lastPhase)
throws IllegalStateException,
InvalidKeyException
Do a phase in the key agreement. The number of times this method is
called depends upon the algorithm and the number of parties
involved, but must be called at least once with the
lastPhase
flag set to true
.
key
- The key for this phase.lastPhase
- Should be true
if this will be the
last phase before generating the shared secret.
- The intermediate result, or
null
if there is
no intermediate result.
generateSecret
public final int generateSecret(byte[] sharedSecret,
int offset)
throws IllegalStateException,
ShortBufferException
Generate the shared secret and store it into the supplied array.
sharedSecret
- The array in which to store the secret.offset
- The index in sharedSecret
to start
storing data.
- The length of the shared secret, in bytes.
getAlgorithm
public final String getAlgorithm()
Return the name of this key-agreement algorithm.
getInstance
public static final KeyAgreement getInstance(String algorithm)
throws NoSuchAlgorithmException
Get an implementation of an algorithm from the first provider that
implements it.
algorithm
- The name of the algorithm to get.
- The proper KeyAgreement instacne, if found.
getInstance
public static final KeyAgreement getInstance(String algorithm,
Provider provider)
throws NoSuchAlgorithmException
Return an implementation of an algorithm from a specific provider.
algorithm
- The name of the algorithm to get.provider
- The provider from which to get the implementation.
- The proper KeyAgreement instance, if found.
getProvider
public final Provider getProvider()
Return the provider of the underlying implementation.
init
public final void init(Key key)
throws InvalidKeyException
Initialize this key agreement with a key. This method will use the
highest-priority
SecureRandom
as its source
of randomness.
key
- The key, usually the user's private key.
init
public final void init(Key key,
SecureRandom random)
throws InvalidKeyException
Initialize this key agreement with a key and a source of
randomness.
key
- The key, usually the user's private key.random
- The source of randomness.
KeyAgreement.java -- Engine for key agreement methods.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.