Java tutorial
//package com.java2s; //License from project: Open Source License import android.util.Log; import java.security.spec.AlgorithmParameterSpec; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; public class Main { static final String TAG = "jamorham cip"; static final byte[] errorbyte = {}; public static byte[] encrypt(byte[] ivBytes, byte[] keyBytes, byte[] textBytes) { try { AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes); SecretKeySpec newKey = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, newKey, ivSpec); return cipher.doFinal(textBytes); } catch (Exception e) { Log.e(TAG, "Error during encryption: " + e.toString()); return errorbyte; } } }