Android AES Decrypt decryptBytes(byte[] data, byte[] key)

Here you can find the source of decryptBytes(byte[] data, byte[] key)

Description

Decrypts data using the AES encryption cipher.

Parameter

Parameter Description
data - Information to be decrypted.
key - Key to use for decryption.

Return

The decrypted data.

Declaration

public static byte[] decryptBytes(byte[] data, byte[] key) 

Method Source Code

//package com.java2s;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;

public class Main {
    /**/*from  w  w w  .  jav  a  2s.  c  o m*/
     * Decrypts data using the AES encryption cipher.
     * 
     * @param data
     *            - Information to be decrypted.
     * @param key
     *            - Key to use for decryption.
     * @return The decrypted data.
     */
    public static byte[] decryptBytes(byte[] data, byte[] key) {
        try {
            Cipher cipher = Cipher.getInstance("AES");
            SecretKeySpec sKey = new SecretKeySpec(key, "AES");
            cipher.init(Cipher.DECRYPT_MODE, sKey);
            return cipher.doFinal(data);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        } catch (BadPaddingException e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. decryptBase64(String content, String key)
  2. decryptBase64(String encryptBase64)
  3. decryptBase64Text(String key, String src)
  4. decryptBytes(String key, byte[] src)
  5. decryptBytes(String seed, byte[] encrypted)
  6. decryptHex(String content, String key)
  7. decryptHex(String content, String username, String password)
  8. decryptNumberWithAES(String encrypted)
  9. decryptUrlDecode(String dataPassword, String encrypted)