}
}
private void testExceptions()
{
SecretKeyFactory skF = null;
try
{
skF = SecretKeyFactory.getInstance("DESede", "BC");
}
catch (Exception e)
{
fail("unexpected exception.", e);
}
KeySpec ks = null;
SecretKey secKey = null;
byte[] bb = new byte[24];
try
{
skF.getKeySpec(null, null);
fail("failed exception test - no exception thrown");
}
catch (InvalidKeySpecException e)
{
// ignore okay
}
catch (Exception e)
{
fail("failed exception test.", e);
}
try
{
ks = (KeySpec)new DESedeKeySpec(bb);
skF.getKeySpec(null, ks.getClass());
fail("failed exception test - no exception thrown");
}
catch (InvalidKeySpecException e)
{
// ignore okay;
}
catch (Exception e)
{
fail("failed exception test.", e);
}
try
{
skF.getKeySpec(secKey, null);
}
catch (InvalidKeySpecException e)
{
// ignore okay
}
catch (Exception e)
{
fail("failed exception test.", e);
}
try
{
KeyGenerator kg = KeyGenerator.getInstance("DESede", "BC");
try
{
kg.init(Integer.MIN_VALUE, new SecureRandom());
fail("failed exception test - no exception thrown");
}
catch (InvalidParameterException e)
{
// ignore okay
}
catch (Exception e)
{
fail("failed exception test.", e);
}
}
catch (Exception e)
{
fail("unexpected exception.", e);
}
try
{
skF = SecretKeyFactory.getInstance("DESede", "BC");
try
{
skF.translateKey(null);
fail("failed exception test - no exception thrown");
}
catch (InvalidKeyException e)
{