APIdia Launch Partner
Top Description Fields Constructors Methods
sun.security.krb5

public Class EncryptionKey

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
sun.security.jgss.krb5.Krb5Util, sun.security.util.*, sun.security.krb5.internal.*, sun.security.krb5.internal.crypto.*, java.io.IOException, java.security.GeneralSecurityException, java.util.Arrays, sun.security.krb5.internal.ktab.KeyTab, sun.security.krb5.internal.ccache.CCacheOutputStream, javax.crypto.spec.DESKeySpec, .DESedeKeySpec

This class encapsulates the concept of an EncryptionKey. An encryption key is defined in RFC 4120 as: EncryptionKey ::= SEQUENCE { keytype [0] Int32 -- actually encryption type --, keyvalue [1] OCTET STRING } keytype This field specifies the encryption type of the encryption key that follows in the keyvalue field. Although its name is "keytype", it actually specifies an encryption type. Previously, multiple cryptosystems that performed encryption differently but were capable of using keys with the same characteristics were permitted to share an assigned number to designate the type of key; this usage is now deprecated. keyvalue This field contains the key itself, encoded as an octet string.

Field Summary

Modifier and TypeField and Description
private int
private byte[]
private Integer
public static final EncryptionKey

Constructor Summary

AccessConstructor and Description
public
EncryptionKey(byte[] keyValue, int keyType, Integer kvno)

public
EncryptionKey(int keyType, byte[] keyValue)

Constructs an EncryptionKey by using the specified key type and key value.

public
EncryptionKey(char[] password, String salt, String algorithm)

public
EncryptionKey(EncryptionKey key)

Generates a sub-sessionkey from a given session key.

public
EncryptionKey(DerValue
a single DER-encoded value.
encoding
)

Constructs an instance of EncryptionKey type.

Method Summary

Modifier and TypeMethod and Description
public static EncryptionKey

Returns:

never null
acquireSecretKey
(PrincipalName
NOT null
cname
,
char[]
NOT null
password
,
int etype, PAData.SaltAndParams
can be NULL
snp
)

Obtains a key for a given etype of a principal with possible new salt and s2kparams

public static EncryptionKey

Returns:

never null
acquireSecretKey
(char[]
NOT null
password
,
String
NOT null
salt
,
int etype, byte[]
can be NULL
s2kparams
)

Obtains a key for a given etype with salt and optional s2kparams

public static EncryptionKey[]

Returns:

an array of secret keys or null if none were found.
acquireSecretKeys
(PrincipalName
the principal whose secret key is desired
princ
,
String
the path to the keytab file. A value of null will be accepted to indicate that the default path should be searched.
keytab
)

Obtains all versions of the secret key of the principal from a keytab.

public static EncryptionKey[]
acquireSecretKeys(char[] password, String salt)

Generate a list of keys using the given principal and password.

public synchronized byte[]

Returns:

byte array of encoded EncryptionKey object.
asn1Encode
()

Returns the ASN.1 encoding of this EncryptionKey.

public synchronized Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public synchronized void
public static EncryptionKey
findKey(int etype, EncryptionKey[] keys)

Find a key with given etype

public static EncryptionKey
findKey(int etype, Integer
if null, return any (first?) key
kvno
,
EncryptionKey[] keys)

Find a key with given etype and kvno

public final byte[]
getBytes()

Returns the raw key bytes, not in any ASN.1 encoding.

public synchronized int
public final Integer
public static EncryptionKey

Returns:

an instance of EncryptionKey.
parse
(DerInputStream
the Der input stream value, which contains one or more marshaled value.
data
,
byte
tag number.
explicitTag
,
boolean
indicate if this data field is optional
optional
)

Parse (unmarshal) an Encryption key from a DER input stream.

private static byte[]
stringToKey(char[] password, String salt, byte[] s2kparams, int keyType)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private static boolean
versionMatches(Integer v1, Integer v2)

Determines if a kvno matches another kvno.

public synchronized void
writeKey(CCacheOutputStream
a CCacheOutputStream to be written to.
cos
)

Writes key value in FCC format to a CCacheOutputStream.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

keyTypeback to summary
private int keyType
keyValueback to summary
private byte[] keyValue
kvnoback to summary
private Integer kvno
NULL_KEYback to summary
public static final EncryptionKey NULL_KEY

Constructor Detail

EncryptionKeyback to summary
public EncryptionKey(byte[] keyValue, int keyType, Integer kvno)
EncryptionKeyback to summary
public EncryptionKey(int keyType, byte[] keyValue)

Constructs an EncryptionKey by using the specified key type and key value. It is used to recover the key when retrieving data from credential cache file.

EncryptionKeyback to summary
public EncryptionKey(char[] password, String salt, String algorithm) throws KrbCryptoException
EncryptionKeyback to summary
public EncryptionKey(EncryptionKey key) throws KrbCryptoException

Generates a sub-sessionkey from a given session key. Used in AcceptSecContextToken and KrbApReq by acceptor- and initiator- side respectively.

EncryptionKeyback to summary
public EncryptionKey(DerValue encoding) throws Asn1Exception, IOException

Constructs an instance of EncryptionKey type.

Parameters
encoding:DerValue

a single DER-encoded value.

Exceptions
Asn1Exception:
if an error occurs while decoding an ASN1 encoded data.
IOException:
if an I/O error occurs while reading encoded data.

Method Detail

acquireSecretKeyback to summary
public static EncryptionKey acquireSecretKey(PrincipalName cname, char[] password, int etype, PAData.SaltAndParams snp) throws KrbException

Obtains a key for a given etype of a principal with possible new salt and s2kparams

Parameters
cname:PrincipalName

NOT null

password:char[]

NOT null

snp:PAData.SaltAndParams

can be NULL

Returns:EncryptionKey

never null

acquireSecretKeyback to summary
public static EncryptionKey acquireSecretKey(char[] password, String salt, int etype, byte[] s2kparams) throws KrbException

Obtains a key for a given etype with salt and optional s2kparams

Parameters
password:char[]

NOT null

salt:String

NOT null

s2kparams:byte[]

can be NULL

Returns:EncryptionKey

never null

acquireSecretKeysback to summary
public static EncryptionKey[] acquireSecretKeys(PrincipalName princ, String keytab)

Obtains all versions of the secret key of the principal from a keytab.

Parameters
princ:PrincipalName

the principal whose secret key is desired

keytab:String

the path to the keytab file. A value of null will be accepted to indicate that the default path should be searched.

Returns:EncryptionKey[]

an array of secret keys or null if none were found.

acquireSecretKeysback to summary
public static EncryptionKey[] acquireSecretKeys(char[] password, String salt) throws KrbException

Generate a list of keys using the given principal and password. Construct a key for each configured etype. Caller is responsible for clearing password.

asn1Encodeback to summary
public synchronized byte[] asn1Encode() throws Asn1Exception, IOException

Returns the ASN.1 encoding of this EncryptionKey.

EncryptionKey ::=   SEQUENCE {
                            keytype[0]    INTEGER,
                            keyvalue[1]   OCTET STRING }

This definition reflects the Network Working Group RFC 4120 specification available at http://www.ietf.org/rfc/rfc4120.txt.

Returns:byte[]

byte array of encoded EncryptionKey object.

Exceptions
Asn1Exception:
if an error occurs while decoding an ASN1 encoded data.
IOException:
if an I/O error occurs while reading encoded data.
cloneback to summary
public synchronized Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

destroyback to summary
public synchronized void destroy()
findKeyback to summary
public static EncryptionKey findKey(int etype, EncryptionKey[] keys) throws KrbException

Find a key with given etype

findKeyback to summary
public static EncryptionKey findKey(int etype, Integer kvno, EncryptionKey[] keys) throws KrbException

Find a key with given etype and kvno

Parameters
kvno:Integer

if null, return any (first?) key

getBytesback to summary
public final byte[] getBytes()

Returns the raw key bytes, not in any ASN.1 encoding.

getETypeback to summary
public synchronized int getEType()
getKeyVersionNumberback to summary
public final Integer getKeyVersionNumber()
parseback to summary
public static EncryptionKey parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException

Parse (unmarshal) an Encryption key from a DER input stream. This form parsing might be used when expanding a value which is part of a constructed sequence and uses explicitly tagged type.

Parameters
data:DerInputStream

the Der input stream value, which contains one or more marshaled value.

explicitTag:byte

tag number.

optional:boolean

indicate if this data field is optional

Returns:EncryptionKey

an instance of EncryptionKey.

Exceptions
Asn1Exception:
if an error occurs while decoding an ASN1 encoded data.
IOException:
if an I/O error occurs while reading encoded data.
stringToKeyback to summary
private static byte[] stringToKey(char[] password, String salt, byte[] s2kparams, int keyType) throws KrbCryptoException
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.

versionMatchesback to summary
private static boolean versionMatches(Integer v1, Integer v2)

Determines if a kvno matches another kvno. Used in the method findKey(type, kvno, keys). Always returns true if either input is null or zero, in case any side does not have kvno info available.

Note

zero is included because N/A is not a legal value for kvno in javax.security.auth.kerberos.KerberosKey. Therefore, the info that the kvno is N/A might be lost when converting between this class and KerberosKey.

writeKeyback to summary
public synchronized void writeKey(CCacheOutputStream cos) throws IOException

Writes key value in FCC format to a CCacheOutputStream.

Parameters
cos:CCacheOutputStream

a CCacheOutputStream to be written to.

Exceptions
IOException:
if an I/O exception occurs.
See Also
sun.security.krb5.internal.ccache.CCacheOutputStream