@Test public void testDecrypt() throws Exception { final Decrypto mockDecrypto = mock(Decrypto.class); final byte[] decodedDataBytes = Base64.decode("data", Base64.DEFAULT); when(mockDecrypto.decrypt(decodedDataBytes)).thenReturn("data".getBytes(Cryptography.CHARSET_NAME)); final String decrypted = CryptoUtils.decrypt("data", mockDecrypto); assertThat(decrypted, is("data")); verify(mockDecrypto).decrypt(decodedDataBytes); }
@Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } }
CryptoUtils { @Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } } }
CryptoUtils { @Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } } private  CryptoUtils(); }
CryptoUtils { @Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } } private  CryptoUtils();  }
CryptoUtils { @Nullable static String decrypt(@Nullable final String value, @NonNull final Decrypto decrypto) { if (value == null || value.length() == 0) { return value; } try { return new String( decrypto.decrypt(Base64.decode(value.getBytes(Cryptography.CHARSET_NAME), Base64.DEFAULT)), Cryptography.CHARSET_NAME ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new AssertionError(Cryptography.CHARSET_NAME + " encoding is not supported!"); } } private  CryptoUtils();   }