@Test public void encrypt() throws Exception { HmacEncryptor encryptor = mock(HmacEncryptor.class); encryptor.delegate = SwapBytesTransformer.encryptor(); when(encryptor.createHmac(any(byte[].class))).thenReturn(new byte[]{0, 1, 2, 3, 4, 5, 6, 7}); when(encryptor.encrypt(any(byte[].class), anyInt(), any(byte[].class))).thenCallRealMethod(); byte[] input = {-1, -2, -3}; byte[] result1 = encryptor.encrypt(input, 0, new byte[1]); assertArrayEquals(new byte[]{8, 0, 1, 2, 3, 4, 5, 6, 7, -3, -2, -1}, result1); byte[] result2 = encryptor.encrypt(input, 5, new byte[1]); assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 8, 0, 1, 2, 3, 4, 5, 6, 7, -3, -2, -1}, result2); }
@Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { byte[] hmac = createHmac(input); byte[] encrypted = delegate.encrypt(input, outputOffset + hmac.length + 1, flags); encrypted[outputOffset++] = (byte)hmac.length; System.arraycopy(hmac, 0, encrypted, outputOffset, hmac.length); return encrypted; }
HmacEncryptor extends HmacCreator implements BytesEncryptor { @Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { byte[] hmac = createHmac(input); byte[] encrypted = delegate.encrypt(input, outputOffset + hmac.length + 1, flags); encrypted[outputOffset++] = (byte)hmac.length; System.arraycopy(hmac, 0, encrypted, outputOffset, hmac.length); return encrypted; } }
HmacEncryptor extends HmacCreator implements BytesEncryptor { @Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { byte[] hmac = createHmac(input); byte[] encrypted = delegate.encrypt(input, outputOffset + hmac.length + 1, flags); encrypted[outputOffset++] = (byte)hmac.length; System.arraycopy(hmac, 0, encrypted, outputOffset, hmac.length); return encrypted; } HmacEncryptor(BytesEncryptor delegate, Header header, Key key); }
HmacEncryptor extends HmacCreator implements BytesEncryptor { @Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { byte[] hmac = createHmac(input); byte[] encrypted = delegate.encrypt(input, outputOffset + hmac.length + 1, flags); encrypted[outputOffset++] = (byte)hmac.length; System.arraycopy(hmac, 0, encrypted, outputOffset, hmac.length); return encrypted; } HmacEncryptor(BytesEncryptor delegate, Header header, Key key); @Override byte[] encrypt(byte[] input, int outputOffset, byte[] flags); }
HmacEncryptor extends HmacCreator implements BytesEncryptor { @Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { byte[] hmac = createHmac(input); byte[] encrypted = delegate.encrypt(input, outputOffset + hmac.length + 1, flags); encrypted[outputOffset++] = (byte)hmac.length; System.arraycopy(hmac, 0, encrypted, outputOffset, hmac.length); return encrypted; } HmacEncryptor(BytesEncryptor delegate, Header header, Key key); @Override byte[] encrypt(byte[] input, int outputOffset, byte[] flags);  }