}
return engine.processBlock(in, 0, in.length);
}
catch (Exception e)
{
throw new BadPaddingException(e.getMessage());
}
}
if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
{
// Generate the ephemeral key pair
ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(ecParams, random));
EphemeralKeyPairGenerator kGen = new EphemeralKeyPairGenerator(gen, new KeyEncoder()
{
public byte[] getEncoded(AsymmetricKeyParameter keyParameter)
{
return ((ECPublicKeyParameters)keyParameter).getQ().getEncoded();
}
});
// Encrypt the buffer
try
{
engine.init(key, params, kGen);
return engine.processBlock(in, 0, in.length);
}
catch (Exception e)
{
throw new BadPaddingException(e.getMessage());
}
}
else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
{
// Decrypt the buffer
try
{
engine.init(key, params, new ECIESPublicKeyParser(ecParams));
return engine.processBlock(in, 0, in.length);
}
catch (InvalidCipherTextException e)
{
throw new BadPaddingException(e.getMessage());
}
}
else
{
throw new IllegalStateException("cipher not initialised");