Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ArrayList<byte[]> encod(String message, SecretKeySpec key) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException, IOException {
- Cipher cifer = Cipher.getInstance("AES/CBC/PKCS5Padding");
- cifer.init(Cipher.ENCRYPT_MODE,key);
- byte[] text=message.getBytes();
- byte[] cifered=cifer.doFinal(text);
- ArrayList<byte[]> array=new ArrayList<>();
- array.add(cifered);
- byte[] encP=cifer.getParameters().getEncoded();
- array.add(encP);
- return array;
- }
- public static String decod(byte[] message,SecretKeySpec key,byte[] parm) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
- Cipher cifer = Cipher.getInstance("AES/CBC/PKCS5Padding");
- AlgorithmParameters aesParams = AlgorithmParameters.getInstance("AES");
- aesParams.init(parm);
- cifer.init(Cipher.DECRYPT_MODE,key,aesParams);
- byte[] text=cifer.doFinal(message);
- return new String(text);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement