I decided to use generic object pooling to reuse cipher object by following A Generic and Concurrent Object Pool . The different is that the article using Connection
I think you're on the correct path. I think you need to initialize the Cipher
in the createNew()
method:
@Override
public Cipher createNew() {
try {
System.out.print("Instances : " + instance);
Cipther result = Cipher.getInstance(this.instance);
result.init(...); // use the right init params, e.g. opmode, crypto key
return result;
} catch (NoSuchAlgorithmException | NoSuchPaddingException se) {
throw new IllegalArgumentException(
"Unable to create new cipher", se);
}
}