Android AES Decrypt decrypt(String dataPassword, String encrypted)

Here you can find the source of decrypt(String dataPassword, String encrypted)

Description

decrypt

License

Apache License

Declaration

public static String decrypt(String dataPassword, String encrypted)
        throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;

public class Main {
    private static final byte[] ENCRYPT_IV = { 0x0, 0x0, 0x0, 0x0, 0x0,
            0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
    private static final String CHARSET = "UTF-8";

    public static String decrypt(String dataPassword, String encrypted)
            throws Exception {
        byte[] byteMi = Base64.decodeBase64(encrypted);
        IvParameterSpec zeroIv = new IvParameterSpec(ENCRYPT_IV);
        SecretKeySpec key = new SecretKeySpec(dataPassword.getBytes(),
                "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, key, zeroIv);
        byte[] decryptedData = cipher.doFinal(byteMi);

        return new String(decryptedData, CHARSET);
    }/*w ww  .  j  a  va2s  . c o  m*/
}

Related

  1. decrypt(String content, String password)
  2. decrypt(String data)
  3. decrypt(String encrypted)
  4. decrypt(String key, String encrypted)
  5. decrypt(String key, String src)
  6. decrypt(String seed, String encrypted)