byte[] salt = new byte[] { 0, 1, 1, 2, 3, 5, 8 };
int iterationCount = 102;
int keyLength = 4;
try
{
new PBEKeySpec(password, salt, iterationCount, keyLength);
}
catch (Exception x)
{
harness.debug(x);
harness.fail("PBEKeySpec() with valid password, salt, iterationCount "
+ "and keyLength failed: " + x);
}
try
{
PBEKeySpec pbeKeySpec = new PBEKeySpec(null, salt, iterationCount,
keyLength);
char[] pbePassword = pbeKeySpec.getPassword();
harness.check(pbePassword.length == 0,
"a null password MUST produce an empty char array");
}
catch (Exception x)
{
harness.debug(x);
harness.fail("PBEKeySpec(password, salt, iterationcount, keyLength) "
+ "with a null password failed: " + x);
}
String msg = "PBEKeySpec() MUST throw NullPointerException if salt is null";
try
{
new PBEKeySpec(password, null, iterationCount, keyLength);
harness.fail(msg);
}
catch (NullPointerException npe)
{
harness.check(true, msg);
}
catch (Exception x)
{
harness.debug(x);
harness.fail(String.valueOf(x));
}
msg = "PBEKeySpec() MUST throw IllegalArgumentException if salt is an "
+ "empty array";
try
{
byte[] emptySalt = new byte[0];
new PBEKeySpec(password, emptySalt, iterationCount, keyLength);
harness.fail(msg);
}
catch (IllegalArgumentException iae)
{
harness.check(true, msg);
}
catch (Exception x)
{
harness.debug(x);
harness.fail(String.valueOf(x));
}
msg = "PBEKeySpec() MUST throw IllegalArgumentException if iterationCount "
+ "is negative";
try
{
new PBEKeySpec(password, salt, - 1, keyLength);
harness.fail(msg);
}
catch (IllegalArgumentException iae)
{
harness.check(true, msg);
}
catch (Exception x)
{
harness.debug(x);
harness.fail(String.valueOf(x));
}
msg = "PBEKeySpec() MUST throw IllegalArgumentException if keyLength is "
+ "negative";
try
{
new PBEKeySpec(password, salt, iterationCount, -1);
harness.fail(msg);
}
catch (IllegalArgumentException iae)
{
harness.check(true, msg);