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); } }
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); } }
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); } }
public static String decode(String msg) { try { SecretKeySpec keySpec = new SecretKeySpec(getKey(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, keySpec); byte[] de64 = DatatypeConverter.parseBase64Binary(msg); byte[] decrypted = cipher.doFinal(de64); return new String(decrypted); } 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); } } }
public static String decode(String msg) { try { SecretKeySpec keySpec = new SecretKeySpec(getKey(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, keySpec); byte[] de64 = DatatypeConverter.parseBase64Binary(msg); byte[] decrypted = cipher.doFinal(de64); return new String(decrypted); } 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); } } }
public static String decode(String msg) { try { SecretKeySpec keySpec = new SecretKeySpec(getKey(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, keySpec); byte[] de64 = DatatypeConverter.parseBase64Binary(msg); byte[] decrypted = cipher.doFinal(de64); return new String(decrypted); } 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); } } }
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); } }
public static String decode(String msg) { try { SecretKeySpec keySpec = new SecretKeySpec(getKey(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, keySpec); byte[] de64 = DatatypeConverter.parseBase64Binary(msg); byte[] decrypted = cipher.doFinal(de64); return new String(decrypted); } 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); } } }