}
else if (params instanceof IvParameterSpec)
{
if (ivLength != 0)
{
param = new ParametersWithIV(new KeyParameter(key.getEncoded()), ((IvParameterSpec)params).getIV());
ivParam = (ParametersWithIV)param;
}
else
{
param = new KeyParameter(key.getEncoded());
}
}
else if (params instanceof RC2ParameterSpec)
{
RC2ParameterSpec rc2Param = (RC2ParameterSpec)params;
param = new RC2Parameters(key.getEncoded(), ((RC2ParameterSpec)params).getEffectiveKeyBits());
if (rc2Param.getIV() != null && ivLength != 0)
{
param = new ParametersWithIV(param, rc2Param.getIV());
ivParam = (ParametersWithIV)param;
}
}
else if (params instanceof RC5ParameterSpec)
{
RC5ParameterSpec rc5Param = (RC5ParameterSpec)params;
param = new RC5Parameters(key.getEncoded(), ((RC5ParameterSpec)params).getRounds());
if (rc5Param.getWordSize() != 32)
{
throw new IllegalArgumentException("can only accept RC5 word size 32 (at the moment...)");
}
if ((rc5Param.getIV() != null) && (ivLength != 0))
{
param = new ParametersWithIV(param, rc5Param.getIV());
ivParam = (ParametersWithIV)param;
}
}
else
{
throw new InvalidAlgorithmParameterException("unknown parameter type.");
}
if ((ivLength != 0) && !(param instanceof ParametersWithIV))
{
if (random == null)
{
random = new SecureRandom();
}
if ((opmode == Cipher.ENCRYPT_MODE) || (opmode == Cipher.WRAP_MODE))
{
byte[] iv = new byte[ivLength];
random.nextBytes(iv);
param = new ParametersWithIV(param, iv);
ivParam = (ParametersWithIV)param;
}
else
{
throw new InvalidAlgorithmParameterException("no IV set when one expected");