@Override public String decrypt(final Key key, final byte[] encryptedValue, final byte[] nonce) throws Exception { throw new IllegalBlockSizeException(""); } });
@Override public String decrypt(final Key key, final byte[] encryptedValue, final byte[] nonce) throws Exception { throw new IllegalBlockSizeException("returns 0x40"); } });
@Override protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { try { byte[] encoded = key.getEncoded(); return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { IllegalBlockSizeException newE = new IllegalBlockSizeException(); newE.initCause(e); throw newE; } }
@Override protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { try { byte[] encoded = key.getEncoded(); return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { IllegalBlockSizeException newE = new IllegalBlockSizeException(); newE.initCause(e); throw newE; } }
@Override protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { try { byte[] encoded = key.getEncoded(); return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { IllegalBlockSizeException newE = new IllegalBlockSizeException(); newE.initCause(e); throw newE; } }
@Override protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { try { byte[] encoded = key.getEncoded(); return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { IllegalBlockSizeException newE = new IllegalBlockSizeException(); newE.initCause(e); throw newE; } }
@Override protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { try { byte[] encoded = key.getEncoded(); return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { IllegalBlockSizeException newE = new IllegalBlockSizeException(); newE.initCause(e); throw newE; } }
@Override protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { try { byte[] encoded = key.getEncoded(); return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { IllegalBlockSizeException newE = new IllegalBlockSizeException(); newE.initCause(e); throw newE; } }
@Override protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { try { byte[] encoded = key.getEncoded(); return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { IllegalBlockSizeException newE = new IllegalBlockSizeException(); newE.initCause(e); throw newE; } }
@Override protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException { try { byte[] encoded = key.getEncoded(); return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { IllegalBlockSizeException newE = new IllegalBlockSizeException(); newE.initCause(e); throw newE; } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
@Test public void matchesCanary_shouldReturnFalseIfInputDataCouldNotBeProccessed_AndC_DecryptReturns_0x40() throws Exception { when(encryptionProvider.decrypt(any(), any(), any())).thenThrow(new IllegalBlockSizeException("returns 0x40")); subject = new ExternalKeyProxy(encryptionKeyMetadata, encryptionProvider); assertFalse(subject.matchesCanary(encryptionKeyCanary)); }
@Test public void matchesCanary_shouldThrowIncorrectKeyException_IfHSMKeyWasWrong() throws Exception { when(encryptionProvider.decrypt(any(), any(), any())).thenThrow(new IllegalBlockSizeException("something bad happened")); subject = new ExternalKeyProxy(encryptionKeyMetadata, encryptionProvider); try { subject.matchesCanary(encryptionKeyCanary); fail("Expected IncorrectKeyException, got none"); } catch (final IncorrectKeyException e) { } catch (final RuntimeException e) { fail("Wrong exception. Expected IncorrectKeyException but got " + e.getClass().toString()); } }
@Test public void encryption_whenTheOperationSucceedsOnlyAfterReconnection_shouldReturnTheEncryptedString() throws Exception { final EncryptedValue expectedEncryption = mock(EncryptedValue.class); when(keySet.getActive()) .thenReturn(firstActiveKey) .thenReturn(secondActiveKey); when(firstActiveKey.encrypt("fake-plaintext")) .thenThrow(new IllegalBlockSizeException("test exception")); when(firstActiveKey.getProvider()).thenReturn(encryptionService); when(secondActiveKey.encrypt("fake-plaintext")) .thenReturn(expectedEncryption); when(secondActiveKey.getProvider()).thenReturn(encryptionService); assertThat(subject.encrypt("fake-plaintext"), equalTo(expectedEncryption)); verify(encryptionService, times(1)) .reconnect(any(IllegalBlockSizeException.class)); verify(keySet, times(1)).reload(); }
@Test public void decrypt_whenTheOperationSucceedsOnlyAfterReconnection() throws Exception { when(keySet.get(activeKeyUuid)) .thenReturn(firstActiveKey) .thenReturn(secondActiveKey); when(keySet.getActive()) .thenReturn(firstActiveKey); when(firstActiveKey .decrypt("fake-encrypted-value".getBytes(StringUtil.UTF_8), "fake-nonce".getBytes(StringUtil.UTF_8))) .thenThrow(new IllegalBlockSizeException("test exception")); when(firstActiveKey.getProvider()).thenReturn(encryptionService); when(secondActiveKey .decrypt("fake-encrypted-value".getBytes(StringUtil.UTF_8), "fake-nonce".getBytes(StringUtil.UTF_8))) .thenReturn("fake-plaintext"); when(secondActiveKey.getProvider()).thenReturn(encryptionService); assertThat(subject .decrypt(new EncryptedValue(activeKeyUuid, "fake-encrypted-value".getBytes(StringUtil.UTF_8), "fake-nonce".getBytes(StringUtil.UTF_8))), equalTo("fake-plaintext")); verify(encryptionService, times(1)) .reconnect(any(IllegalBlockSizeException.class)); verify(keySet, times(1)).reload(); }