Java AES Descrypt aesDecryptByBytes(byte[] encryptBytes, String decryptKey)

Here you can find the source of aesDecryptByBytes(byte[] encryptBytes, String decryptKey)

Description

aes Decrypt By Bytes

License

Open Source License

Declaration

public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) 

Method Source Code

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

import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;

public class Main {

    public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) {
        if (encryptBytes == null || decryptKey == null) {
            return null;
        }//from  ww  w.  ja v a2s . c o m
        try {
            KeyGenerator kgen = KeyGenerator.getInstance("AES");
            kgen.init(128, new SecureRandom(decryptKey.getBytes()));

            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
            byte[] decryptBytes = cipher.doFinal(encryptBytes);
            return new String(decryptBytes);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. aesDecrypt(byte[] content, Key key)
  2. AESDecrypt(byte[] encrypted, byte[] key, byte[] iv)
  3. aesDecrypt(byte[] input, Key key)
  4. aesDecrypt(String encryptStr, String decryptKey)