String principalName = "hnelson@EXAMPLE.COM";
String passPhrase = "secret";
Map<EncryptionType, EncryptionKey> map = KerberosKeyFactory.getKerberosKeys( principalName, passPhrase );
EncryptionKey kerberosKey = map.get( EncryptionType.DES_CBC_MD5 );
EncryptionType keyType = kerberosKey.getKeyType();
int keyLength = kerberosKey.getKeyValue().length;
byte[] keyBytes = kerberosKey.getKeyValue();
assertEquals( keyType, EncryptionType.DES_CBC_MD5 );
assertEquals( keyLength, 8 );
byte[] expectedBytes = new byte[]
{ ( byte ) 0xF4, ( byte ) 0xA7, ( byte ) 0x13, ( byte ) 0x64, ( byte ) 0x8A, ( byte ) 0x61, ( byte ) 0xCE,
( byte ) 0x5B };
assertTrue( Arrays.equals( expectedBytes, keyBytes ) );
kerberosKey = map.get( EncryptionType.DES3_CBC_SHA1_KD );
keyType = kerberosKey.getKeyType();
keyLength = kerberosKey.getKeyValue().length;
keyBytes = kerberosKey.getKeyValue();
assertEquals( keyType, EncryptionType.DES3_CBC_SHA1_KD );
assertEquals( keyLength, 24 );
expectedBytes = new byte[]
{ ( byte ) 0x57, ( byte ) 0x07, ( byte ) 0xCE, ( byte ) 0x29, ( byte ) 0x52, ( byte ) 0x92, ( byte ) 0x2C,
( byte ) 0x1C, ( byte ) 0x8C, ( byte ) 0xBF, ( byte ) 0x43, ( byte ) 0xC2, ( byte ) 0x3D,
( byte ) 0x8F, ( byte ) 0x8C, ( byte ) 0x5E, ( byte ) 0x9E, ( byte ) 0x8C, ( byte ) 0xF7,
( byte ) 0x5D, ( byte ) 0x3E, ( byte ) 0x4A, ( byte ) 0x5E, ( byte ) 0x25 };
assertTrue( Arrays.equals( expectedBytes, keyBytes ) );
kerberosKey = map.get( EncryptionType.RC4_HMAC );
keyType = kerberosKey.getKeyType();
keyLength = kerberosKey.getKeyValue().length;
keyBytes = kerberosKey.getKeyValue();
assertEquals( keyType, EncryptionType.RC4_HMAC );
assertEquals( keyLength, 16 );
expectedBytes = new byte[]
{ ( byte ) 0x87, ( byte ) 0x8D, ( byte ) 0x80, ( byte ) 0x14, ( byte ) 0x60, ( byte ) 0x6C, ( byte ) 0xDA,
( byte ) 0x29, ( byte ) 0x67, ( byte ) 0x7A, ( byte ) 0x44, ( byte ) 0xEF, ( byte ) 0xA1,
( byte ) 0x35, ( byte ) 0x3F, ( byte ) 0xC7 };
assertTrue( Arrays.equals( expectedBytes, keyBytes ) );
kerberosKey = map.get( EncryptionType.AES128_CTS_HMAC_SHA1_96 );
keyType = kerberosKey.getKeyType();
keyLength = kerberosKey.getKeyValue().length;
keyBytes = kerberosKey.getKeyValue();
assertEquals( keyType, EncryptionType.AES128_CTS_HMAC_SHA1_96 );
assertEquals( keyLength, 16 );
expectedBytes = new byte[]
{ ( byte ) 0xAD, ( byte ) 0x21, ( byte ) 0x4B, ( byte ) 0x38, ( byte ) 0xB6, ( byte ) 0x9D, ( byte ) 0xFC,
( byte ) 0xCA, ( byte ) 0xAC, ( byte ) 0xF1, ( byte ) 0x5F, ( byte ) 0x34, ( byte ) 0x6D,
( byte ) 0x41, ( byte ) 0x7B, ( byte ) 0x90 };
assertTrue( Arrays.equals( expectedBytes, keyBytes ) );
kerberosKey = map.get( EncryptionType.AES256_CTS_HMAC_SHA1_96 );
if ( kerberosKey != null )
{
keyType = kerberosKey.getKeyType();
keyLength = kerberosKey.getKeyValue().length;
keyBytes = kerberosKey.getKeyValue();
assertEquals( keyType, EncryptionType.AES256_CTS_HMAC_SHA1_96 );
assertEquals( keyLength, 32 );
expectedBytes = new byte[]
{ ( byte ) 0x3D, ( byte ) 0x33, ( byte ) 0x31, ( byte ) 0x8F, ( byte ) 0xBE, ( byte ) 0x47,