Here you can find the source of crypt(byte[] text, byte[] key, int mode)
@SuppressLint("TrulyRandom") public static byte[] crypt(byte[] text, byte[] key, int mode) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
//package com.java2s; import android.annotation.SuppressLint; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; public class Main { @SuppressLint("TrulyRandom") public static byte[] crypt(byte[] text, byte[] key, int mode) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto"); sr.setSeed(key);// w ww . j ava 2s .c o m kgen.init(256, sr); SecretKey sk = kgen.generateKey(); SecretKeySpec k = new SecretKeySpec(sk.getEncoded(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(mode, k); return cipher.doFinal(text); } }