Android Utililty Methods AES Encrypt

List of utility methods to do AES Encrypt

Description

The list of methods to do AES Encrypt are organized into topic(s).

Method

byte[]encrypt(byte[] data, byte[] key)
encrypt
return encrypt(data, key, DEFAULT_CIPHER_ALGORITHM);
byte[]encrypt(byte[] data, byte[] key, String cipherAlgorithm)
encrypt
Key k = toKey(key);
return encrypt(data, k, cipherAlgorithm);
byte[]encrypt(byte[] key, byte[] src)
encrypt
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
return cipher.doFinal(src);
byte[]encrypt(byte[] key, byte[] src)
encrypt
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(src);
return encrypted;
byte[]encrypt(byte[] raw, byte[] clear)
encrypt
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES"); 
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
byte[]encrypt(byte[] raw, byte[] clear)
encrypt
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
byte[]encrypt(byte[] raw, byte[] clear)
encrypt
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(
        new byte[cipher.getBlockSize()]));
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
byte[]encrypt(byte[] raw, byte[] clear)
Actual encrypt data function.
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(
        new byte[cipher.getBlockSize()]));
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
byte[]encrypt(byte[] source)
encrypt
if (source == null || source.length < 1) {
    return null;
return encryptCipher.doFinal(source);
StringencryptBase64(String content, String key)
encrypt Base
try {
    byte[] res = encrypt(content.getBytes(UTF_8), key);
    return new String(Base64.encodeBase64(res), UTF_8);
} catch (Exception e) {
    e.printStackTrace();
return null;