### Question:
RandomKeyFactory { public static Map<EncryptionType, EncryptionKey> getRandomKeys() throws KerberosException { return getRandomKeys( DEFAULT_CIPHERS.keySet() ); }  static Map<EncryptionType, EncryptionKey> getRandomKeys(); static Map<EncryptionType, EncryptionKey> getRandomKeys( Set<EncryptionType> ciphers ); static EncryptionKey getRandomKey( EncryptionType encryptionType );  }### Answer:
@Test public void testRandomKeyFactory() throws Exception { Map<EncryptionType, EncryptionKey> map = RandomKeyFactory.getRandomKeys(); EncryptionKey kerberosKey = map.get( EncryptionType.DES_CBC_MD5 ); EncryptionType keyType = kerberosKey.getKeyType(); int keyLength = kerberosKey.getKeyValue().length; assertEquals( EncryptionType.DES_CBC_MD5, keyType ); assertEquals( 8, keyLength ); kerberosKey = map.get( EncryptionType.DES3_CBC_SHA1_KD ); keyType = kerberosKey.getKeyType(); keyLength = kerberosKey.getKeyValue().length; assertEquals( EncryptionType.DES3_CBC_SHA1_KD, keyType ); assertEquals( 24, keyLength ); kerberosKey = map.get( EncryptionType.RC4_HMAC ); keyType = kerberosKey.getKeyType(); keyLength = kerberosKey.getKeyValue().length; if ( VendorHelper.isArcFourHmacSupported() ) { assertEquals( EncryptionType.RC4_HMAC, keyType ); assertEquals( 16, keyLength ); } kerberosKey = map.get( EncryptionType.AES128_CTS_HMAC_SHA1_96 ); keyType = kerberosKey.getKeyType(); keyLength = kerberosKey.getKeyValue().length; assertEquals( EncryptionType.AES128_CTS_HMAC_SHA1_96, keyType ); assertEquals( 16, keyLength ); kerberosKey = map.get( EncryptionType.AES256_CTS_HMAC_SHA1_96 ); keyType = kerberosKey.getKeyType(); keyLength = kerberosKey.getKeyValue().length; assertEquals( EncryptionType.AES256_CTS_HMAC_SHA1_96, keyType ); assertEquals( 32, keyLength ); }
@Test public void testRandomKeyFactoryOnlyDes() throws Exception { Set<EncryptionType> encryptionTypes = new HashSet<EncryptionType>(); encryptionTypes.add( EncryptionType.DES_CBC_MD5 ); Map<EncryptionType, EncryptionKey> map = RandomKeyFactory.getRandomKeys( encryptionTypes ); assertEquals( "List length", 1, map.values().size() ); EncryptionKey kerberosKey = map.get( EncryptionType.DES_CBC_MD5 ); EncryptionType keyType = kerberosKey.getKeyType(); int keyLength = kerberosKey.getKeyValue().length; assertEquals( EncryptionType.DES_CBC_MD5, keyType); assertEquals( 8, keyLength ); }