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

pack-priv final Class DHPrivateKey

extends Object
implements PrivateKey, DHPrivateKey, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.crypto.interfaces.DHPrivateKey, java.security.PrivateKey, javax.security.auth.Destroyable, 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, .PrivateKey, .InvalidKeyException, javax.crypto.spec.DHParameterSpec, sun.security.util.*

A private key in PKCS#8 format for the Diffie-Hellman key agreement algorithm.
Author
Jan Luehe
See Also
DHPublicKey, javax.crypto.KeyAgreement

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private byte[]
private final BigInteger
g

private byte[]
private final int
l

private final BigInteger
p

private static final BigInteger
private static final long
private final BigInteger
x

Constructor Summary

AccessConstructor and Description
pack-priv
DHPrivateKey(BigInteger
the private value
x
,
BigInteger
the prime modulus
p
,
BigInteger
the base generator
g
)

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

pack-priv
DHPrivateKey(BigInteger
the private value
x
,
BigInteger
the prime modulus
p
,
BigInteger
the base generator
g
,
int
the private-value length
l
)

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

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

Make a DH private key from its DER encoding (PKCS #8).

Method Summary

Modifier and TypeMethod and Description
private static DHPrivateKey.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: "PKCS#8"

public DHParameterSpec

Returns:

the key parameters
getParams
()

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

Returns the key parameters.

public BigInteger

Returns:

the private value, x
getX
()

Implements javax.crypto.interfaces.DHPrivateKey.getX.

Returns the private value, x.

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.

private Object

Returns:

the standard KeyRep object to be serialized
writeReplace
()

Replace the DH private key to be serialized.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

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
PKCS8_VERSIONback to summary
private static final BigInteger PKCS8_VERSION
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.security.PrivateKey.serialVersionUID, javax.crypto.interfaces.DHPrivateKey.serialVersionUID.

Annotations
@Serial
xback to summary
private final BigInteger x

Constructor Detail

DHPrivateKeyback to summary
pack-priv DHPrivateKey(BigInteger x, BigInteger p, BigInteger g) throws InvalidKeyException

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

Parameters
x:BigInteger

the private value

p:BigInteger

the prime modulus

g:BigInteger

the base generator

DHPrivateKeyback to summary
pack-priv DHPrivateKey(BigInteger x, BigInteger p, BigInteger g, int l)

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

Parameters
x:BigInteger

the private value

p:BigInteger

the prime modulus

g:BigInteger

the base generator

l:int

the private-value length

DHPrivateKeyback to summary
pack-priv DHPrivateKey(byte[] encodedKey) throws InvalidKeyException

Make a DH private key from its DER encoding (PKCS #8).

Parameters
encodedKey:byte[]

the encoded key

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

Method Detail

decodeback to summary
private static DHPrivateKey.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: "PKCS#8"

getParamsback to summary
public DHParameterSpec getParams()

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

Returns the key parameters.

Returns:DHParameterSpec

the key parameters

getXback to summary
public BigInteger getX()

Implements javax.crypto.interfaces.DHPrivateKey.getX.

Returns the private value, x.

Returns:BigInteger

the private value, x

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
writeReplaceback to summary
private Object writeReplace() throws ObjectStreamException

Replace the DH private key to be serialized.

Returns:Object

the standard KeyRep object to be serialized

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

private Class DHPrivateKey.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
x

Constructor Summary

AccessConstructor and Description
pack-priv
DHComponents(BigInteger x, 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
xback to summary
pack-priv final BigInteger x

Constructor Detail

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