Java AES decrypt_aes(String key, String initVector, String encrypted)

Here you can find the source of decrypt_aes(String key, String initVector, String encrypted)

Description

decrypaes

License

Open Source License

Declaration

public static String decrypt_aes(String key, String initVector, String encrypted) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.DatatypeConverter;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.IvParameterSpec;

public class Main {
    public static String decrypt_aes(String key, String initVector, String encrypted) {
        try {//w ww .ja  v  a 2  s. c  o m
            IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
            SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
            byte[] original = cipher.doFinal(DatatypeConverter.parseBase64Binary(encrypted));

            return new String(original);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return null;
    }
}

Related

  1. aesHandler(byte[] toBeHandleData, String password, boolean isEncrypt)
  2. aesKey(int keySize)
  3. aesStoreKeyToFile(Key secretKey, String path)
  4. createSessionKey()
  5. decrypt(String encryptedText, String key)
  6. encryptAes(String value)
  7. encryptDecrypt(int mode, String data, String key, String salt, String iv)
  8. getAesKey(String key)