/**
* @tests javax.security.auth.kerberos.KerberosKey#getEncoded()
*/
public void test_getEncoded() {
KerberosKey key = new KerberosKey(principal, keyBytes, 1, 123);
byte[] keyBytes1 = key.getEncoded();
assertTrue("encoded", Arrays.equals(keyBytes, keyBytes1));
// bytes are copied each time we invoke the method
assertNotSame("keyBytes immutability 1 ", keyBytes, keyBytes1);
assertNotSame("keyBytes immutability 2 ", keyBytes1, key.getEncoded());
// Test generation of DES key from password
// test data from RFC 3961 (http://www.ietf.org/rfc/rfc3961.txt)
// see A.2 test vectors
// test data format: principal/password/DES key
Object[][] testcases = {
{
"raeburn@ATHENA.MIT.EDU",
"password",
new byte[] { (byte) 0xcb, (byte) 0xc2, (byte) 0x2f,
(byte) 0xae, (byte) 0x23, (byte) 0x52,
(byte) 0x98, (byte) 0xe3 } },
{
"danny@WHITEHOUSE.GOV",
"potatoe",
new byte[] { (byte) 0xdf, (byte) 0x3d, (byte) 0x32,
(byte) 0xa7, (byte) 0x4f, (byte) 0xd9,
(byte) 0x2a, (byte) 0x01 } },
// TODO add "pianist@EXAMPLE.COM" and "Juri ... @ATHENA.MIT.EDU"
};
for (Object[] element : testcases) {
KerberosPrincipal kp = new KerberosPrincipal(
(String) element[0], 1);
key = new KerberosKey(kp, ((String) element[1]).toCharArray(),
"DES");
assertTrue("Testcase: " + (String) element[0], Arrays.equals(
(byte[]) element[2], key.getEncoded()));
}
}