@Test public void testEncode() { testString("test"); testString("topolino"); testString(""); }
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); } }
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); } } }
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); } }  }
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); }
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);  }