Android AES Decrypt decryptUrlDecode(String dataPassword, String encrypted)

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

Description

decrypt Url Decode

License

Apache License

Declaration

public static String decryptUrlDecode(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;

import java.net.URLDecoder;

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 decryptUrlDecode(String dataPassword,
            String encrypted) throws Exception {
        return decrypt(dataPassword, URLDecoder.decode(encrypted, CHARSET));
    }/*w w  w .  java  2 s  .c  o m*/

    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);
    }
}

Related

  1. decryptBytes(String seed, byte[] encrypted)
  2. decryptBytes(byte[] data, byte[] key)
  3. decryptHex(String content, String key)
  4. decryptHex(String content, String username, String password)
  5. decryptNumberWithAES(String encrypted)
  6. aesDecode(String seed, String encrypted)
  7. decrypt(byte[] raw, byte[] encrypted)
  8. decrypt(Context context, String encrypted)
  9. decrypt(Context context, String encrypted)