Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public static ArrayList<byte[]> encod(String message, SecretKeySpec key) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException, IOException {
  2. Cipher cifer = Cipher.getInstance("AES/CBC/PKCS5Padding");
  3. cifer.init(Cipher.ENCRYPT_MODE,key);
  4. byte[] text=message.getBytes();
  5. byte[] cifered=cifer.doFinal(text);
  6. ArrayList<byte[]> array=new ArrayList<>();
  7. array.add(cifered);
  8. byte[] encP=cifer.getParameters().getEncoded();
  9. array.add(encP);
  10. return array;
  11. }
  12. public static String decod(byte[] message,SecretKeySpec key,byte[] parm) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
  13. Cipher cifer = Cipher.getInstance("AES/CBC/PKCS5Padding");
  14. AlgorithmParameters aesParams = AlgorithmParameters.getInstance("AES");
  15. aesParams.init(parm);
  16. cifer.init(Cipher.DECRYPT_MODE,key,aesParams);
  17. byte[] text=cifer.doFinal(message);
  18. return new String(text);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement