APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.crypto.provider

pack-priv final Class DHPublicKey

extends Object
implements PublicKey, DHPublicKey, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.crypto.interfaces.DHPublicKey, java.security.PublicKey, java.security.AsymmetricKey, java.security.BinaryEncodable, java.security.Key, javax.crypto.interfaces.DHKey
Imports
java.io.*, java.util.Arrays, .Objects, java.math.BigInteger, java.security.KeyRep, .InvalidKeyException, .PublicKey, javax.crypto.spec.DHParameterSpec, sun.security.util.*

A public key in X.509 format for the Diffie-Hellman key agreement algorithm.
Author
Jan Luehe
See Also
DHPrivateKey, javax.crypto.KeyAgreement

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static final ObjectIdentifier
private byte[]
private final BigInteger
g

private byte[]
private final int
l

private final BigInteger
p

private static final long
private final BigInteger
y

Constructor Summary

AccessConstructor and Description
pack-priv
DHPublicKey(BigInteger
the public value
y
,
BigInteger
the prime modulus
p
,
BigInteger
the base generator
g
)

Make a DH public key out of a public value y, a prime modulus p, and a base generator g.

pack-priv
DHPublicKey(BigInteger
the public value
y
,
BigInteger
the prime modulus
p
,
BigInteger
the base generator
g
,
int
the private-value length
l
)

Make a DH public key out of a public value y, a prime modulus p, a base generator g, and a private-value length l.

pack-priv
DHPublicKey(byte[]
the encoded key
encodedKey
)

Make a DH public key from its DER encoding (X.509).

Method Summary

Modifier and TypeMethod and Description
private static DHPublicKey.DHComponents
decode(byte[] encodedKey)

private static byte[]
encode(BigInteger p, BigInteger g, int l, byte[] key)

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String
getAlgorithm()

Implements java.security.Key.getAlgorithm.

Returns the name of the algorithm associated with this key: "DH"

public synchronized byte[]
getEncoded()

Implements java.security.Key.getEncoded.

Get the encoding of the key.

public String
getFormat()

Implements java.security.Key.getFormat.

Returns the encoding format of this key: "X.509"

public DHParameterSpec

Returns:

the key parameters
getParams
()

Overrides default java.security.AsymmetricKey.getParams, javax.crypto.interfaces.DHPublicKey.getParams.

Returns the key parameters.

public BigInteger

Returns:

the public value, y
getY
()

Implements javax.crypto.interfaces.DHPublicKey.getY.

Returns the public value, y.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Calculates a hash code value for the object.

private void
readObject(ObjectInputStream
the ObjectInputStream from which data is read
stream
)

Restores the state of this object from the stream.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private Object

Returns:

the standard KeyRep object to be serialized
writeReplace
()

Replace the DH public key to be serialized.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

DH_OIDback to summary
pack-priv static final ObjectIdentifier DH_OID
encodedKeyback to summary
private byte[] encodedKey
gback to summary
private final BigInteger g
keyback to summary
private byte[] key
lback to summary
private final int l
pback to summary
private final BigInteger p
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.security.PublicKey.serialVersionUID, javax.crypto.interfaces.DHPublicKey.serialVersionUID.

Annotations
@Serial
yback to summary
private final BigInteger y

Constructor Detail

DHPublicKeyback to summary
pack-priv DHPublicKey(BigInteger y, BigInteger p, BigInteger g) throws InvalidKeyException

Make a DH public key out of a public value y, a prime modulus p, and a base generator g.

Parameters
y:BigInteger

the public value

p:BigInteger

the prime modulus

g:BigInteger

the base generator

Exceptions
InvalidKeyException:
if the key cannot be encoded
DHPublicKeyback to summary
pack-priv DHPublicKey(BigInteger y, BigInteger p, BigInteger g, int l)

Make a DH public key out of a public value y, a prime modulus p, a base generator g, and a private-value length l.

Parameters
y:BigInteger

the public value

p:BigInteger

the prime modulus

g:BigInteger

the base generator

l:int

the private-value length

DHPublicKeyback to summary
pack-priv DHPublicKey(byte[] encodedKey) throws InvalidKeyException

Make a DH public key from its DER encoding (X.509).

Parameters
encodedKey:byte[]

the encoded key

Exceptions
InvalidKeyException:
if the encoded key does not represent a Diffie-Hellman public key

Method Detail

decodeback to summary
private static DHPublicKey.DHComponents decode(byte[] encodedKey) throws IOException
encodeback to summary
private static byte[] encode(BigInteger p, BigInteger g, int l, byte[] key)
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getAlgorithmback to summary
public String getAlgorithm()

Implements java.security.Key.getAlgorithm.

Returns the name of the algorithm associated with this key: "DH"

getEncodedback to summary
public synchronized byte[] getEncoded()

Implements java.security.Key.getEncoded.

Get the encoding of the key.

getFormatback to summary
public String getFormat()

Implements java.security.Key.getFormat.

Returns the encoding format of this key: "X.509"

getParamsback to summary
public DHParameterSpec getParams()

Overrides default java.security.AsymmetricKey.getParams, javax.crypto.interfaces.DHPublicKey.getParams.

Returns the key parameters.

Returns:DHParameterSpec

the key parameters

getYback to summary
public BigInteger getY()

Implements javax.crypto.interfaces.DHPublicKey.getY.

Returns the public value, y.

Returns:BigInteger

the public value, y

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Calculates a hash code value for the object. Objects that are equal will also have the same hashcode.

Annotations
@Override
readObjectback to summary
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException

Restores the state of this object from the stream.

JDK 1.5+ objects use KeyReps instead.

Parameters
stream:ObjectInputStream

the ObjectInputStream from which data is read

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if a serialized class cannot be loaded
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

writeReplaceback to summary
private Object writeReplace() throws ObjectStreamException

Replace the DH public key to be serialized.

Returns:Object

the standard KeyRep object to be serialized

Annotations
@Serial
Exceptions
ObjectStreamException:
if a new object representing this DH public key could not be created
com.sun.crypto.provider back to summary

private Class DHPublicKey.DHComponents

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final BigInteger
g

pack-priv final byte[]
pack-priv final int
l

pack-priv final BigInteger
p

pack-priv final BigInteger
y

Constructor Summary

AccessConstructor and Description
pack-priv
DHComponents(BigInteger y, BigInteger p, BigInteger g, int l, byte[] key)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

gback to summary
pack-priv final BigInteger g
keyback to summary
pack-priv final byte[] key
lback to summary
pack-priv final int l
pback to summary
pack-priv final BigInteger p
yback to summary
pack-priv final BigInteger y

Constructor Detail

DHComponentsback to summary
pack-priv DHComponents(BigInteger y, BigInteger p, BigInteger g, int l, byte[] key)