public static interface LocalSingleHttpServer.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 IOException
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
in the same place.
// you are free to choose your own Initialization Vector byte[] initialIV = new byte[16]; return rebaseCipher(initialIV);
IOException
- If the object can not be created.Cipher rebaseCipher(byte[] iv) throws IOException
Example of implementation:
Cipher c = null; try { // avoid the default security provider "AndroidOpenSSL" as of Android 4.3 c = Cipher.getInstance("AES/CTR/NoPadding", "BC"); c.init(Cipher.DECRYPT_MODE, new SecretKeySpec("1234567890123456".getBytes(), "AES"), new IvParameterSpec(iv)); } catch (GeneralSecurityException e) { throw new IOException("Unable to create a cipher", e); } return c;
iv
- The computed IV to consider.IOException
- If the object can not be created.