Java AES Encrypt aesEncrypt(byte[] source, Key key)

Here you can find the source of aesEncrypt(byte[] source, Key key)

Description

aes Encrypt

License

Open Source License

Declaration

public static byte[] aesEncrypt(byte[] source, Key key) 

Method Source Code


//package com.java2s;
import java.security.Key;

import javax.crypto.Cipher;

public class Main {
    public static final String AES_ALGORITHM_NAME = "AES";

    public static byte[] aesEncrypt(byte[] source, Key key) {

        try {/*from   w ww .j  a v a  2 s  .  c o m*/
            Cipher cipher = Cipher.getInstance(AES_ALGORITHM_NAME);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            return cipher.doFinal(source);
        } catch (Exception e) {
            throw new IllegalStateException("AES ecnrypt error", e);
        }
    }
}

Related

  1. aesEncrypt(String content, String encryptKey)
  2. aesEncrypt(String content, String key)
  3. aesEncryptBytes(byte[] pBytes, SecretKeySpec pKeySpec, IvParameterSpec ivParameterSpec)
  4. aesEncryptToBytes(String content, String encryptKey)