APIdia Launch Partner
Top Description Fields Constructors Methods
javax.security.auth.kerberos

pack-priv Class KeyImpl

extends Object
implements SecretKey, Destroyable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.security.auth.Destroyable, javax.crypto.SecretKey, java.security.Key
Imports
java.io.*, java.util.Arrays, javax.crypto.SecretKey, javax.security.auth.Destroyable, .DestroyFailedException, sun.security.jgss.krb5.Krb5Util, sun.security.krb5.Asn1Exception, .PrincipalName, .EncryptionKey, .EncryptedData, .KrbException, sun.security.util.DerValue

This class encapsulates a Kerberos encryption key. It is not associated with a principal and may represent an ephemeral session key.
Author
Mayank Upadhyay
Since
1.4

Field Summary

Modifier and TypeField and Description
private transient volatile boolean
private transient byte[]
private transient int
private static final long

Constructor Summary

AccessConstructor and Description
public
KeyImpl(byte[]
the raw bytes for the secret key
keyBytes
,
int
the key type for the secret key as defined by the Kerberos protocol specification.
keyType
)

Constructs a KeyImpl from the given bytes.

public
KeyImpl(KerberosPrincipal
the principal from which to derive the salt
principal
,
char[]
the password that should be used to compute the key.
password
,
String
the name for the algorithm that this key will be used for. This parameter may be null in which case "DES" will be assumed.
algorithm
)

Constructs a KeyImpl from a password.

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Overrides default javax.security.auth.Destroyable.destroy.

Destroy this Object.

public boolean
equals(Object other)

Overrides java.lang.Object.equals.

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

public final String
getAlgorithm()

Implements java.security.Key.getAlgorithm.

Returns the standard algorithm name for this key.

private String
getAlgorithmName(int eType)

public final byte[]
getEncoded()

Implements java.security.Key.getEncoded.

Returns the key in its primary encoding format, or null if this key does not support encoding.

public final String
getFormat()

Implements java.security.Key.getFormat.

Returns the name of the primary encoding format of this key, or null if this key does not support encoding.

public final int
getKeyType()

Returns the keyType for this key as defined in the Kerberos Spec.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
isDestroyed()

Overrides default javax.security.auth.Destroyable.isDestroyed.

Determine if this Object has been destroyed.

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

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 void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
oos
)

Writes the state of this object to the stream.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

destroyedback to summary
private transient volatile boolean destroyed
keyBytesback to summary
private transient byte[] keyBytes
keyTypeback to summary
private transient int keyType
serialVersionUIDback to summary
private static final long serialVersionUID

Hides javax.crypto.SecretKey.serialVersionUID.

Annotations
@Serial

Constructor Detail

KeyImplback to summary
public KeyImpl(byte[] keyBytes, int keyType)

Constructs a KeyImpl from the given bytes.

Parameters
keyBytes:byte[]

the raw bytes for the secret key

keyType:int

the key type for the secret key as defined by the Kerberos protocol specification.

KeyImplback to summary
public KeyImpl(KerberosPrincipal principal, char[] password, String algorithm)

Constructs a KeyImpl from a password.

Parameters
principal:KerberosPrincipal

the principal from which to derive the salt

password:char[]

the password that should be used to compute the key.

algorithm:String

the name for the algorithm that this key will be used for. This parameter may be null in which case "DES" will be assumed.

Method Detail

destroyback to summary
public void destroy() throws DestroyFailedException

Overrides default javax.security.auth.Destroyable.destroy.

Doc from javax.security.auth.Destroyable.destroy.

Destroy this Object.

Sensitive information associated with this Object is destroyed or cleared. Subsequent calls to certain methods on this Object will result in an IllegalStateException being thrown.

Exceptions
DestroyFailedException:
if the destroy operation fails.
equalsback to summary
public boolean equals(Object other)

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.

getAlgorithmback to summary
public final String getAlgorithm()

Implements java.security.Key.getAlgorithm.

Doc from java.security.Key.getAlgorithm.

Returns the standard algorithm name for this key. For example, "RSA" would indicate that this key is an RSA key. See the Key Algorithms section in the Java Security Standard Algorithm Names Specification for information about standard key algorithm names.

getAlgorithmNameback to summary
private String getAlgorithmName(int eType)
getEncodedback to summary
public final byte[] getEncoded()

Implements java.security.Key.getEncoded.

Doc from java.security.Key.getEncoded.

Returns the key in its primary encoding format, or null if this key does not support encoding.

getFormatback to summary
public final String getFormat()

Implements java.security.Key.getFormat.

Doc from java.security.Key.getFormat.

Returns the name of the primary encoding format of this key, or null if this key does not support encoding. The primary encoding format is named in terms of the appropriate ASN.1 data format, if an ASN.1 specification for this key exists. For example, the name of the ASN.1 data format for public keys is SubjectPublicKeyInfo, as defined by the X.509 standard; in this case, the returned format is "X.509". Similarly, the name of the ASN.1 data format for private keys is PrivateKeyInfo, as defined by the PKCS #8 standard; in this case, the returned format is "PKCS#8".

getKeyTypeback to summary
public final int getKeyType()

Returns the keyType for this key as defined in the Kerberos Spec.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
isDestroyedback to summary
public boolean isDestroyed()

Overrides default javax.security.auth.Destroyable.isDestroyed.

Doc from javax.security.auth.Destroyable.isDestroyed.

Determine if this Object has been destroyed.

readObjectback to summary
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException

Restores the state of this object from the stream.

Parameters
ois: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.

writeObjectback to summary
private void writeObject(ObjectOutputStream oos) throws IOException

Writes the state of this object to the stream.

Parameters
oos:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs }
Serial data
this KeyImpl is serialized by writing out the ASN.1 Encoded bytes of the encryption key. The ASN.1 encoding is defined in RFC4120 as follows: EncryptionKey ::= SEQUENCE { keytype [0] Int32 -- actually encryption type --, keyvalue [1] OCTET STRING