public interface CipherFactory
setCipherFactory() method.| Modifier and Type | Method and Description |
|---|---|
Cipher |
getCipher()
Returns the initial cipher, that is with the initial IV.
|
Cipher |
rebaseCipher(byte[] iv)
Returns a new cipher, created with a computed IV in place of the initial IV.
|
Cipher getCipher() throws GeneralSecurityException
In case you also use it, setCipher()
has precedence over this method, which you can simply implement as returning null.
But this is not a recommended design: a better approach is to group all cipher related actions
at the same place.
// you are free to choose your own Initialization Vector byte[] initialIV = new byte[16]; return rebaseCipher(initialIV);
GeneralSecurityException - If the object cannot be created.Cipher rebaseCipher(byte[] iv) throws GeneralSecurityException
Example of implementation:
// avoid the default security provider "AndroidOpenSSL" in Android 4.3+
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
c.init(Cipher.DECRYPT_MODE,
new SecretKeySpec("1234567890123456".getBytes(), "AES"),
new IvParameterSpec(iv));
return c;
iv - The computed IV to consider.GeneralSecurityException - If the object cannot be created.