@Test public void should_encrypt2() throws CipherException { assertThat(CipherUtils.encrypt(PLAIN_TEXT2, KEY1), is(CIPHER_TEXT2)); }
public static String encrypt(String plainText, String key) throws CipherException { try { Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE); cipher.init(Cipher.ENCRYPT_MODE, stringToKey(key)); byte[] encrypted = Base64.getEncoder().encode(cipher.doFinal(plainText.getBytes(UTF_8))); return new String(encrypted, UTF_8); } catch (Exception e) { throw new CipherException("Cannot encrypt", e); } }
CipherUtils { public static String encrypt(String plainText, String key) throws CipherException { try { Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE); cipher.init(Cipher.ENCRYPT_MODE, stringToKey(key)); byte[] encrypted = Base64.getEncoder().encode(cipher.doFinal(plainText.getBytes(UTF_8))); return new String(encrypted, UTF_8); } catch (Exception e) { throw new CipherException("Cannot encrypt", e); } } }
CipherUtils { public static String encrypt(String plainText, String key) throws CipherException { try { Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE); cipher.init(Cipher.ENCRYPT_MODE, stringToKey(key)); byte[] encrypted = Base64.getEncoder().encode(cipher.doFinal(plainText.getBytes(UTF_8))); return new String(encrypted, UTF_8); } catch (Exception e) { throw new CipherException("Cannot encrypt", e); } }  }
CipherUtils { public static String encrypt(String plainText, String key) throws CipherException { try { Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE); cipher.init(Cipher.ENCRYPT_MODE, stringToKey(key)); byte[] encrypted = Base64.getEncoder().encode(cipher.doFinal(plainText.getBytes(UTF_8))); return new String(encrypted, UTF_8); } catch (Exception e) { throw new CipherException("Cannot encrypt", e); } }  static String encrypt(String plainText, String key); static String decrypt(String cipherText, String key); }
CipherUtils { public static String encrypt(String plainText, String key) throws CipherException { try { Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE); cipher.init(Cipher.ENCRYPT_MODE, stringToKey(key)); byte[] encrypted = Base64.getEncoder().encode(cipher.doFinal(plainText.getBytes(UTF_8))); return new String(encrypted, UTF_8); } catch (Exception e) { throw new CipherException("Cannot encrypt", e); } }  static String encrypt(String plainText, String key); static String decrypt(String cipherText, String key);  }