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

StringencryptBase64(byte[] source)
encrypt Base
if (source == null || source.length < 1) {
    return null;
byte[] encrypted = encryptCipher.doFinal(source);
return Base64.encodeToString(encrypted, Base64.NO_WRAP);
byte[]encryptBytes(String seed, byte[] cleartext)
encrypt Bytes
byte[] rawKey = getRawKey(seed.getBytes());
byte[] result = encrypt(rawKey, cleartext);
return result;
byte[]encryptBytes(byte[] data, byte[] key)
Encrypts data using the AES encryption cipher.
try {
    Cipher cipher = Cipher.getInstance("AES");
    SecretKeySpec sKey = new SecretKeySpec(key, "AES");
    cipher.init(Cipher.ENCRYPT_MODE, sKey);
    return cipher.doFinal(data);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
} catch (NoSuchPaddingException e) {
...
StringencryptHex(String content, String key)
encrypt Hex
try {
    byte[] res = encrypt(content.getBytes(UTF_8), key);
    return hexEncode(res);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
return null;
StringencryptHex(String content, String username, String password)
encrypt Hex
return encryptHex(content, password + username);
StringencryptNumberWithAES(String number)
encrypt Number With AES
byte[] numberToEncryptBytes = number.getBytes();
String keyString = "intrepidlearner1"; 
byte[] key = keyString.getBytes();
Cipher c = Cipher.getInstance("AES");
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
c.init(Cipher.ENCRYPT_MODE, keySpec);
byte[] encryptedData = c.doFinal(numberToEncryptBytes);
return android.util.Base64.encodeToString(encryptedData,
...
StringencryptToBase64Text(String key, String src)
encrypt To Base Text
byte[] result = encryptToBytes(key, src);
return new String(Base64.encode(result, Base64.DEFAULT));
byte[]encryptToBytes(String key, String src)
encrypt To Bytes
byte[] rawKey = getRawKey(key);
return encrypt(rawKey, src.getBytes());
StringencryptUrlEncode(String dataPassword, String cleartext)
encrypt Url Encode
return URLEncoder.encode(encrypt(dataPassword, cleartext), CHARSET);
HashMapencryptWithKey(String key, String src)
encrypt With Key
HashMap<String, String> encryptionMap = new HashMap<String, String>();
try {
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    encryptionMap.put("iv", ENCRYPTION_IV);
    cipher.init(Cipher.ENCRYPT_MODE, makeKey(key),
            makeIv(encryptionMap.get("iv")));
    encryptionMap.put("encrypted", Base64.encodeToString(
            cipher.doFinal(src.getBytes()), Base64.NO_WRAP));
...