|
Project home | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.aha.u4jsp.dh.TwoPartyDhKeyAgreement
public final class TwoPartyDhKeyAgreement
Object that represents data needed to set up secure communication between two parties using Diffie-Hellman secret key agreement.
This does not replace but uses the Java cryptography API class
DHParameterSpec:
serializable: may be of use (persistent storage) to
the unit that is the centralized owner of the parameters (i.e. a server).
public key and symmetric cipher parameters (the
later using
attributes).
An example on this is the
DhSecureServerProtocol that store a
SymmetricCipherSpec object as an attribute that is picked up by
client side
DhSecureClientProtocol.
Example of use in a client / server system:
Properties using
TwoPartyDhKeyAgreement(Properties).
Alternatively if parameters has not been stored (i.e. the very first
launch of a service or data lost) the server can create parameters using
the constructors
TwoPartyDhKeyAgreement() and
TwoPartyDhKeyAgreement(int).
The
main(String[]) of this class can be used to create parameters
stored in a
Properties file that can be read by
TwoPartyDhKeyAgreement(Properties).
Since computing these parameters may take some time (in the order of
a minute) it may be an advantage to prepare such a property file not on
server startup time.
An alternative is to use
TwoPartyDhKeyAgreement(Properties) but not define any
these parameters with properties, then the ones of the
SKIP protocol will be used.
this (item 1) but before
accepting any requests (part of startup) invokes
generateKeyPair() to generate it's key pair.
this
serialized to the clients.
Note that the server's private key property of this is
not transmitted over open air since it is transient data.
getPublicKey() to fetch the server's public key and then
invokes
generateKeyPair() to compute it's key pair.
generateSecretKey(PublicKey, String) to compute the secret key
to use for encryption and decryption.
Resources on Diffie-Hellman key agreement:
When
created from a
Properties where the following properties may be defined:
| Property | Description | Mandatory |
|---|---|---|
u4jsp.crypto.dh-g |
The base generator g used. |
Only if
u4jsp.crypto.dh-p is given: if none of the
Diffie-Hellman key agreement parameters are given those of the
SKIP protocol are used.
|
u4jsp.crypto.dh-p |
The prime modulus p used. |
Only if
u4jsp.crypto.dh-g is given: if none of the
Diffie-Hellman key agreement parameters are given those of the
SKIP protocol are used.
|
This class'
main program can be used to generate the
Diffie-Hellman parameters in a property file as described above, this may
be a convenient way to start making a properties file for server side
protocol persistence.
DHParameterSpec,
KeyAgreement,
KeyPairGenerator,
PrivateKey,
PublicKey,
Serialized Form| Constructor Summary | |
|---|---|
TwoPartyDhKeyAgreement()
Creates parameters using a bit size of 1024. |
|
TwoPartyDhKeyAgreement(java.math.BigInteger p,
java.math.BigInteger g)
Constructor. |
|
TwoPartyDhKeyAgreement(javax.crypto.spec.DHParameterSpec s)
Constructor. |
|
TwoPartyDhKeyAgreement(int size)
Constructor. |
|
TwoPartyDhKeyAgreement(java.util.Properties props)
Constructor. |
|
TwoPartyDhKeyAgreement(java.lang.String p,
java.lang.String g)
Constructor. |
|
| Method Summary | |
|---|---|
void |
generateKeyPair()
Generates a public key /
private key pair using this set of
parameters. |
javax.crypto.SecretKey |
generateSecretKey(java.security.PublicKey otherPk,
java.lang.String cipher)
Generates secret key given other party's public key and name on symmetric cipher to be used for data encryption/decryption. |
java.util.Properties |
getAsProperties()
Return as properties
getP(),
getG(). |
java.util.Properties |
getAsProperties(java.util.Properties props)
Return as properties
getP(),
getG(). |
java.lang.Object |
getAttribute(java.lang.String name)
Gets attribute value. |
java.math.BigInteger |
getG()
Gets the base generator g. |
java.math.BigInteger |
getP()
Gets the prime modulus p. |
java.security.PrivateKey |
getPrivateKey()
Gets the private key generated by
generateKeyPair(). |
java.security.PublicKey |
getPublicKey()
Gets the public key generated by
generateKeyPair(). |
javax.crypto.spec.DHParameterSpec |
getSpec()
Gets the DHParameterSpec representing the parameters needed as input to
Java cryptographic methods. |
static void |
main(java.lang.String[] args)
Program that can be used to create a property file with newly generated Diffie-Helmann key agreement parameters that TwoPartyDhKeyAgreement(Properties) accepts. |
void |
removeAttribute(java.lang.String name)
Removes attribute. |
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Sets attribute value. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TwoPartyDhKeyAgreement(javax.crypto.spec.DHParameterSpec s)
Constructor.
s - Specification to get parameters from.
public TwoPartyDhKeyAgreement(java.lang.String p,
java.lang.String g)
Constructor.
p - getP()'s
String representation.g - getG()'s
String representation.
public TwoPartyDhKeyAgreement(java.math.BigInteger p,
java.math.BigInteger g)
Constructor.
p - getP().g - getG().public TwoPartyDhKeyAgreement()
Creates parameters using a bit size of 1024.
public TwoPartyDhKeyAgreement(int size)
Constructor.
size - The number of bits.
java.lang.IllegalArgumentException - If size<1.public TwoPartyDhKeyAgreement(java.util.Properties props)
Constructor.
See here for the properties that may be defined that are specific for the Diffie-Hellman key agreement protocol.
props - Properties to construct from as produced by
getAsProperties().
java.lang.IllegalArgumentException - If does not accept props.getAsProperties()| Method Detail |
|---|
public java.math.BigInteger getP()
Gets the prime modulus p.
public java.math.BigInteger getG()
Gets the base generator g.
public javax.crypto.spec.DHParameterSpec getSpec()
Gets the
DHParameterSpec representing the parameters needed as input to
Java cryptographic methods.
DHParameterSpec.public void generateKeyPair()
Generates a
public key /
private key pair using this set of
parameters.
If pair has been generated this method does nothing.
getPublicKey(),
getPrivateKey()public java.security.PublicKey getPublicKey()
Gets the
public key generated by
generateKeyPair().
PublicKey or null if
generateKeyPair() has never been invoked.generateKeyPair(),
getPrivateKey()public java.security.PrivateKey getPrivateKey()
Gets the
private key generated by
generateKeyPair().
Note that this property is transient: It will not be serialized
since this information is not to be send over insecure line and the
main use of the serializable feature is to send this over a
insecure line.
PrivateKey or null if
generateKeyPair() has never been invoked.generateKeyPair(),
getPublicKey()
public void setAttribute(java.lang.String name,
java.lang.Object value)
Sets attribute value.
name - Attribute name.value - Attribute value. May not be null, use
removeAttribute(String) to remove.
java.lang.IllegalArgumentException - If value is not serializable.public java.lang.Object getAttribute(java.lang.String name)
Gets attribute value.
name - Attribute name.
null if not found.public void removeAttribute(java.lang.String name)
Removes attribute.
name - Attribute name.public java.util.Properties getAsProperties()
public java.util.Properties getAsProperties(java.util.Properties props)
Return as
properties
getP(),
getG().
props - Optional
Properties to store in, if null allocates.
Properties.TwoPartyDhKeyAgreement(Properties)
public javax.crypto.SecretKey generateSecretKey(java.security.PublicKey otherPk,
java.lang.String cipher)
Generates secret key given other party's public key and name on symmetric cipher to be used for data encryption/decryption.
In the case that this party's
private key has not been generated this
method does so by invoking
generateKeyPair().
otherPk - Other party's public key.cipher - Cipher algorithm name.
java.lang.IllegalArgumentException - If cipher does not identify an
symmetric cipher algorithm through
KeyAgreement.generateSecret().public java.lang.String toString()
toString in class java.lang.Objectpublic static void main(java.lang.String[] args)
Program that can be used to create a property file with newly generated
Diffie-Helmann key agreement parameters that
TwoPartyDhKeyAgreement(Properties) accepts.
Accepts command line options:
| Option | Description | Mandatory |
|---|---|---|
-verbose |
Prints to
standard out generated Diffie-Hellman key
agreement parameters.
|
No |
-size <size> |
The number of bits. |
No, default value is 1024.
|
-file <path> |
File to write to.
If file exists properties will be loaded first and written again.
Note that any existing properties named
U4jspNames.DH_P,
U4jspNames.DH_G will get new values since these are the
Diffie-Hellman key agreement parameters.
|
No, if missing a file named security.properties is
produced in current directory.
|
args - Command line arguments, see above table.
|
Project home | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||