javax.security.auth.kerberos
Class KerberosKey

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.security.auth.kerberos.KerberosKey
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable , Key sample code for java.security.Key definition code for java.security.Key , javax.crypto.SecretKey, Destroyable sample code for javax.security.auth.Destroyable definition code for javax.security.auth.Destroyable

public class KerberosKey
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements javax.crypto.SecretKey, Destroyable sample code for javax.security.auth.Destroyable definition code for javax.security.auth.Destroyable

This class encapsulates a long term secret key for a Kerberos principal.

All Kerberos JAAS login modules that obtain a principal's password and generate the secret key from it should use this class. Where available, the login module might even read this secret key directly from a Kerberos "keytab". Sometimes, such as when authenticating a server in the absence of user-to-user authentication, the login module will store an instance of this class in the private credential set of a Subject sample code for javax.security.auth.Subject definition code for javax.security.auth.Subject during the commit phase of the authentication process.

It might be necessary for the application to be granted a PrivateCredentialPermission sample code for javax.security.auth.PrivateCredentialPermission definition code for javax.security.auth.PrivateCredentialPermission if it needs to access the KerberosKey instance from a Subject. This permission is not needed when the application depends on the default JGSS Kerberos mechanism to access the KerberosKey. In that case, however, the application will need an appropriate ServicePermission sample code for javax.security.auth.kerberos.ServicePermission definition code for javax.security.auth.kerberos.ServicePermission .

Since:
1.4
See Also:
Serialized Form

Constructor Summary
KerberosKey sample code for javax.security.auth.kerberos.KerberosKey.KerberosKey(javax.security.auth.kerberos.KerberosPrincipal, byte[], int, int) definition code for javax.security.auth.kerberos.KerberosKey.KerberosKey(javax.security.auth.kerberos.KerberosPrincipal, byte[], int, int) (KerberosPrincipal sample code for javax.security.auth.kerberos.KerberosPrincipal definition code for javax.security.auth.kerberos.KerberosPrincipal  principal, byte[] keyBytes, int keyType, int versionNum)
          Constructs a KerberosKey from the given bytes when the key type and key version number are known.
KerberosKey sample code for javax.security.auth.kerberos.KerberosKey.KerberosKey(javax.security.auth.kerberos.KerberosPrincipal, char[], java.lang.String) definition code for javax.security.auth.kerberos.KerberosKey.KerberosKey(javax.security.auth.kerberos.KerberosPrincipal, char[], java.lang.String) (KerberosPrincipal sample code for javax.security.auth.kerberos.KerberosPrincipal definition code for javax.security.auth.kerberos.KerberosPrincipal  principal, char[] password, String sample code for java.lang.String definition code for java.lang.String  algorithm)
          Constructs a KerberosKey from a principal's password.
 
Method Summary
 void destroy sample code for javax.security.auth.kerberos.KerberosKey.destroy() definition code for javax.security.auth.kerberos.KerberosKey.destroy() ()
          Destroys this key.
 String sample code for java.lang.String definition code for java.lang.String getAlgorithm sample code for javax.security.auth.kerberos.KerberosKey.getAlgorithm() definition code for javax.security.auth.kerberos.KerberosKey.getAlgorithm() ()
          Returns the standard algorithm name for this key.
 byte[] getEncoded sample code for javax.security.auth.kerberos.KerberosKey.getEncoded() definition code for javax.security.auth.kerberos.KerberosKey.getEncoded() ()
          Returns the key material of this secret key.
 String sample code for java.lang.String definition code for java.lang.String getFormat sample code for javax.security.auth.kerberos.KerberosKey.getFormat() definition code for javax.security.auth.kerberos.KerberosKey.getFormat() ()
          Returns the name of the encoding format for this secret key.
 int getKeyType sample code for javax.security.auth.kerberos.KerberosKey.getKeyType() definition code for javax.security.auth.kerberos.KerberosKey.getKeyType() ()
          Returns the key type for this long-term key.
 KerberosPrincipal sample code for javax.security.auth.kerberos.KerberosPrincipal definition code for javax.security.auth.kerberos.KerberosPrincipal getPrincipal sample code for javax.security.auth.kerberos.KerberosKey.getPrincipal() definition code for javax.security.auth.kerberos.KerberosKey.getPrincipal() ()
          Returns the principal that this key belongs to.
 int getVersionNumber sample code for javax.security.auth.kerberos.KerberosKey.getVersionNumber() definition code for javax.security.auth.kerberos.KerberosKey.getVersionNumber() ()
          Returns the key version number.
 boolean isDestroyed sample code for javax.security.auth.kerberos.KerberosKey.isDestroyed() definition code for javax.security.auth.kerberos.KerberosKey.isDestroyed() ()
          Determines if this key has been destroyed.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for javax.security.auth.kerberos.KerberosKey.toString() definition code for javax.security.auth.kerberos.KerberosKey.toString() ()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

KerberosKey sample code for javax.security.auth.kerberos.KerberosKey(javax.security.auth.kerberos.KerberosPrincipal, byte[], int, int) definition code for javax.security.auth.kerberos.KerberosKey(javax.security.auth.kerberos.KerberosPrincipal, byte[], int, int)

public KerberosKey(KerberosPrincipal sample code for javax.security.auth.kerberos.KerberosPrincipal definition code for javax.security.auth.kerberos.KerberosPrincipal  principal,
                   byte[] keyBytes,
                   int keyType,
                   int versionNum)
Constructs a KerberosKey from the given bytes when the key type and key version number are known. This can be used when reading the secret key information from a Kerberos "keytab".

Parameters:
principal - the principal that this secret key belongs to
keyBytes - the raw bytes for the secret key
keyType - the key type for the secret key as defined by the Kerberos protocol specification.
versionNum - the version number of this secret key

KerberosKey sample code for javax.security.auth.kerberos.KerberosKey(javax.security.auth.kerberos.KerberosPrincipal, char[], java.lang.String) definition code for javax.security.auth.kerberos.KerberosKey(javax.security.auth.kerberos.KerberosPrincipal, char[], java.lang.String)

public KerberosKey(KerberosPrincipal sample code for javax.security.auth.kerberos.KerberosPrincipal definition code for javax.security.auth.kerberos.KerberosPrincipal  principal,
                   char[] password,
                   String sample code for java.lang.String definition code for java.lang.String  algorithm)
Constructs a KerberosKey from a principal's password.

Parameters:
principal - the principal that this password belongs to
password - the password that should be used to compute the key
algorithm - the name for the algorithm that this key will be used for. This parameter may be null in which case the default algorithm "DES" will be assumed.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the name of the algorithm passed is unsupported.
Method Detail

getPrincipal sample code for javax.security.auth.kerberos.KerberosKey.getPrincipal() definition code for javax.security.auth.kerberos.KerberosKey.getPrincipal()

public final KerberosPrincipal sample code for javax.security.auth.kerberos.KerberosPrincipal definition code for javax.security.auth.kerberos.KerberosPrincipal  getPrincipal()
Returns the principal that this key belongs to.

Returns:
the principal this key belongs to.

getVersionNumber sample code for javax.security.auth.kerberos.KerberosKey.getVersionNumber() definition code for javax.security.auth.kerberos.KerberosKey.getVersionNumber()

public final int getVersionNumber()
Returns the key version number.

Returns:
the key version number.

getKeyType sample code for javax.security.auth.kerberos.KerberosKey.getKeyType() definition code for javax.security.auth.kerberos.KerberosKey.getKeyType()

public final int getKeyType()
Returns the key type for this long-term key.

Returns:
the key type.

getAlgorithm sample code for javax.security.auth.kerberos.KerberosKey.getAlgorithm() definition code for javax.security.auth.kerberos.KerberosKey.getAlgorithm()

public final String sample code for java.lang.String definition code for java.lang.String  getAlgorithm()
Returns the standard algorithm name for this key. For example, "DES" would indicate that this key is a DES key. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.

Specified by:
getAlgorithm sample code for java.security.Key.getAlgorithm() definition code for java.security.Key.getAlgorithm() in interface Key sample code for java.security.Key definition code for java.security.Key
Returns:
the name of the algorithm associated with this key.

getFormat sample code for javax.security.auth.kerberos.KerberosKey.getFormat() definition code for javax.security.auth.kerberos.KerberosKey.getFormat()

public final String sample code for java.lang.String definition code for java.lang.String  getFormat()
Returns the name of the encoding format for this secret key.

Specified by:
getFormat sample code for java.security.Key.getFormat() definition code for java.security.Key.getFormat() in interface Key sample code for java.security.Key definition code for java.security.Key
Returns:
the String "RAW"

getEncoded sample code for javax.security.auth.kerberos.KerberosKey.getEncoded() definition code for javax.security.auth.kerberos.KerberosKey.getEncoded()

public final byte[] getEncoded()
Returns the key material of this secret key.

Specified by:
getEncoded sample code for java.security.Key.getEncoded() definition code for java.security.Key.getEncoded() in interface Key sample code for java.security.Key definition code for java.security.Key
Returns:
the key material

destroy sample code for javax.security.auth.kerberos.KerberosKey.destroy() definition code for javax.security.auth.kerberos.KerberosKey.destroy()

public void destroy()
             throws DestroyFailedException sample code for javax.security.auth.DestroyFailedException definition code for javax.security.auth.DestroyFailedException 
Destroys this key. A call to any of its other methods after this will cause an IllegalStateException to be thrown.

Specified by:
destroy sample code for javax.security.auth.Destroyable.destroy() definition code for javax.security.auth.Destroyable.destroy() in interface Destroyable sample code for javax.security.auth.Destroyable definition code for javax.security.auth.Destroyable
Throws:
DestroyFailedException sample code for javax.security.auth.DestroyFailedException definition code for javax.security.auth.DestroyFailedException - if some error occurs while destorying this key.

isDestroyed sample code for javax.security.auth.kerberos.KerberosKey.isDestroyed() definition code for javax.security.auth.kerberos.KerberosKey.isDestroyed()

public boolean isDestroyed()
Determines if this key has been destroyed.

Specified by:
isDestroyed sample code for javax.security.auth.Destroyable.isDestroyed() definition code for javax.security.auth.Destroyable.isDestroyed() in interface Destroyable sample code for javax.security.auth.Destroyable definition code for javax.security.auth.Destroyable
Returns:
true if this Object has been destroyed, false otherwise.

toString sample code for javax.security.auth.kerberos.KerberosKey.toString() definition code for javax.security.auth.kerberos.KerberosKey.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Description copied from class: Object sample code for java.lang.Object.toString() definition code for java.lang.Object.toString()
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a string representation of the object.