### Question:
PwEncoder { public static String encode(String msg) { try { SecretKeySpec keySpec = new SecretKeySpec(getKey(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, keySpec); byte[] input = msg.getBytes(); byte[] encrypted = cipher.doFinal(input); return DatatypeConverter.printBase64Binary(encrypted); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException("Error while encoding", ex); } catch (NoSuchPaddingException ex) { throw new RuntimeException("Error while encoding", ex); } catch (IllegalBlockSizeException ex) { throw new RuntimeException("Error while encoding", ex); } catch (BadPaddingException ex) { throw new RuntimeException("Error while encoding", ex); } catch (InvalidKeyException ex) { throw new RuntimeException("Error while encoding", ex); } }  static String encode(String msg); static String decode(String msg);  }### Answer:
@Test public void testEncode() { testString("test"); testString("topolino"); testString(""); }
@Test public void cannotDecodePwWithCustomKey() throws Exception { Properties originalProperties = System.getProperties(); Properties properties = new Properties(); properties.putAll(originalProperties); System.setProperties(properties); properties.setProperty("GEOFENCE_PWENCODER_KEY", "mycustomkeyforencrypting"); String encoded = PwEncoder.encode("test"); System.out.println(encoded); String defaultKey = "installation dependant key needed"; byte[] bytes = defaultKey.substring(0, 16).getBytes(); SecretKeySpec keySpec = new SecretKeySpec(bytes, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, keySpec); try { cipher.doFinal(Base64.decodeBase64(encoded)); fail(); } catch (GeneralSecurityException e) { } System.setProperties(originalProperties); }