Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

javax.crypto
Class KeyAgreement  view KeyAgreement download KeyAgreement.java

java.lang.Object
  extended byjavax.crypto.KeyAgreement

public class KeyAgreement
extends java.lang.Object

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.

Since:
1.4

Field Summary
private  java.lang.String algorithm
          The name of this instance's algorithm.
private  KeyAgreementSpi kaSpi
          The underlying key agreement implementation.
private  java.security.Provider provider
          The provider of this implementation.
private static java.lang.String SERVICE
           
private  boolean virgin
          Singnals whether or not this instance has been initialized.
 
Constructor Summary
protected KeyAgreement(KeyAgreementSpi kaSpi, java.security.Provider provider, java.lang.String algorithm)
           
 
Method Summary
 java.security.Key doPhase(java.security.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(java.lang.String algorithm)
          Generate the shared secret and return it as an appropriate SecretKey.
 java.lang.String getAlgorithm()
          Return the name of this key-agreement algorithm.
static KeyAgreement getInstance(java.lang.String algorithm)
          Get an implementation of an algorithm from the first provider that implements it.
static KeyAgreement getInstance(java.lang.String algorithm, java.security.Provider provider)
          Get an implementation of an algorithm from a specific provider.
static KeyAgreement getInstance(java.lang.String algorithm, java.lang.String provider)
          Get an implementation of an algorithm from a named provider.
 java.security.Provider getProvider()
          Return the provider of the underlying implementation.
 void init(java.security.Key key)
          Initialize this key agreement with a key.
 void init(java.security.Key key, java.security.spec.AlgorithmParameterSpec params)
          Initialize this key agreement with a key and parameters.
 void init(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)
          Initialize this key agreement with a key, parameters, and source of randomness.
 void init(java.security.Key key, java.security.SecureRandom random)
          Initialize this key agreement with a key and a source of randomness.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVICE

private static final java.lang.String SERVICE
See Also:
Constant Field Values

kaSpi

private KeyAgreementSpi kaSpi
The underlying key agreement implementation.


provider

private java.security.Provider provider
The provider of this implementation.


algorithm

private java.lang.String algorithm
The name of this instance's algorithm.


virgin

private boolean virgin
Singnals whether or not this instance has been initialized.

Constructor Detail

KeyAgreement

protected KeyAgreement(KeyAgreementSpi kaSpi,
                       java.security.Provider provider,
                       java.lang.String algorithm)
Method Detail

getInstance

public static final KeyAgreement getInstance(java.lang.String algorithm)
                                      throws java.security.NoSuchAlgorithmException
Get an implementation of an algorithm from the first provider that implements it.


getInstance

public static final KeyAgreement getInstance(java.lang.String algorithm,
                                             java.lang.String provider)
                                      throws java.security.NoSuchAlgorithmException,
                                             java.security.NoSuchProviderException
Get an implementation of an algorithm from a named provider.


getInstance

public static final KeyAgreement getInstance(java.lang.String algorithm,
                                             java.security.Provider provider)
                                      throws java.security.NoSuchAlgorithmException
Get an implementation of an algorithm from a specific provider.


doPhase

public final java.security.Key doPhase(java.security.Key key,
                                       boolean lastPhase)
                                throws java.lang.IllegalStateException,
                                       java.security.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.


generateSecret

public final byte[] generateSecret()
                            throws java.lang.IllegalStateException
Generate the shared secret in a new byte array.


generateSecret

public final int generateSecret(byte[] sharedSecret,
                                int offset)
                         throws java.lang.IllegalStateException,
                                ShortBufferException
Generate the shared secret and store it into the supplied array.


generateSecret

public final SecretKey generateSecret(java.lang.String algorithm)
                               throws java.lang.IllegalStateException,
                                      java.security.InvalidKeyException,
                                      java.security.NoSuchAlgorithmException
Generate the shared secret and return it as an appropriate SecretKey.


getAlgorithm

public final java.lang.String getAlgorithm()
Return the name of this key-agreement algorithm.


getProvider

public final java.security.Provider getProvider()
Return the provider of the underlying implementation.


init

public final void init(java.security.Key key)
                throws java.security.InvalidKeyException
Initialize this key agreement with a key. This method will use the highest-priority java.security.SecureRandom as its source of randomness.


init

public final void init(java.security.Key key,
                       java.security.SecureRandom random)
                throws java.security.InvalidKeyException
Initialize this key agreement with a key and a source of randomness.


init

public final void init(java.security.Key key,
                       java.security.spec.AlgorithmParameterSpec params)
                throws java.security.InvalidAlgorithmParameterException,
                       java.security.InvalidKeyException
Initialize this key agreement with a key and parameters. This method will use the highest-priority java.security.SecureRandom as its source of randomness.


init

public final void init(java.security.Key key,
                       java.security.spec.AlgorithmParameterSpec params,
                       java.security.SecureRandom random)
                throws java.security.InvalidAlgorithmParameterException,
                       java.security.InvalidKeyException
Initialize this key agreement with a key, parameters, and source of randomness.