Android AES Decrypt decrypt(byte[] textBytes, String key)

Here you can find the source of decrypt(byte[] textBytes, String key)

Description

decrypt

Declaration

public static byte[] decrypt(byte[] textBytes, String key)
            throws java.io.UnsupportedEncodingException,
            NoSuchAlgorithmException, NoSuchPaddingException,
            InvalidKeyException, InvalidAlgorithmParameterException,
            IllegalBlockSizeException, BadPaddingException 

Method Source Code

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

public class Main {
    private static byte[] ivBytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

    public static byte[] decrypt(byte[] textBytes, String key)
            throws java.io.UnsupportedEncodingException,
            NoSuchAlgorithmException, NoSuchPaddingException,
            InvalidKeyException, InvalidAlgorithmParameterException,
            IllegalBlockSizeException, BadPaddingException {

        byte[] keyBytes = key.getBytes("UTF-8");

        AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes);
        SecretKeySpec newKey = new SecretKeySpec(keyBytes, "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, newKey, ivSpec);
        return cipher.doFinal(textBytes);
    }//from   www  .  ja  v  a2 s.  co  m
}

Related

  1. decrypt(byte[] key, byte[] src)
  2. decrypt(byte[] raw, byte[] encrypted)
  3. decrypt(byte[] raw, byte[] encrypted)
  4. decrypt(byte[] raw, byte[] encrypted)
  5. decrypt(byte[] raw, byte[] encrypted)
  6. decryptBase64(String content, String key)
  7. decryptBase64(String encryptBase64)
  8. decryptBase64Text(String key, String src)
  9. decryptBytes(String key, byte[] src)